Delphi to achieve suspended karaoke subtitles

Source: Internet
Author: User
Tags dname transparent watermark

GDI + realizes transparent watermark and text recently added watermark function to "JPEG browse scaler", in the process of design, reference the article on the net, but found that the GDI + API package used by the article is not the one that I use now, the GDI + API package currently used by Delphi has two sets, The set includes directdraw.*, gdipapi.*, gdipobj.*, gdiputil.* as filenames, and another set of gdipexport.*, gdiplus.*, gdiptypes.*, gdiputil.* as filenames, I use the former, the article is the latter, so the article original code according to the set of GDI + API package I used to modify, the modified code is as follows:

USES Gdiputil,gdipapi,gdipobj;

Procedure form1.savejpg (sname,dname:string);

sname-source JPEG file name, dname-JPEG file name after watermark

Const

Colormatrix:tcolormatrix =
( //r G B A V
(1.0, 0.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0, 0.0),
(0.0, 0.0, 0.0, 0.3, 0.0),
(0.0, 0.0, 0.0, 0.0, 1.0)
);
Var
Font1:tgpfont;
Bmp,watermark:tgpbitmap;
G:tgpgraphics;
Sb1:tgpsolidbrush;
Imageattr:tgpimageattributes;
Jpg:tgpimage;
Strformat:tgpstringformat;
Encoderclsid:tguid;
Parameters:tencoderparameters;
Quality:integer;

Begin

//Loading JPEG images
Jpg:=tgpimage.create (sname);
//Create a BMP based on the size of the JPEG image
BMP: = tgpbitmap.create (jpg). Getwidth,jpg. GetHeight, Pixelformat32bpprgb);

Draw a JPEG Basemap
G: = Tgpgraphics.create (BMP);
G.setinterpolationmode (interpolationmodehighqualitybicubic);
G.drawimage (JPG, makerect (0, 0, Jpg.getwidth,,jpg.getheight), 0, 0, jpg.getwidth, Jpg.getheight, Unitpixel);

Use BMP format image in image control to make watermark map
Watermark:=tgpbitmap.create (Image1.Picture.Bitmap.Handle, PIXELFORMAT32BPPRGB);
 

Set the watermark's opacity to 0.3 (according to ColorMatrix's [3][3]=0.3)
Imageattr: = tgpimageattributes.create;
Imageattr.setcolormatrix (ColorMatrix:);

//Draw watermark, position in the upper left corner of the original x=20,y=20 bit, force the size to 100*100.
G.drawimage (Watermark, Makerec (20,20, 100,100), 0, 0
Image1.picture.bitmap.width,image1.picture.bitmap.height, Unitpixel, imageattr);

Add watermark Text

Font1: = Tgpfont.create (' blackbody ', 20);

SB1: = Tgpsolidbrush.create ($50000000); Black Shadow Bottom
SB2: = Tgpsolidbrush.create ($50FFFFFF); White word on top

Strformat: = tgpstringformat.create;
Strformat.setalignment (stringalignmentnear);

Use black and white to stagger 1 pixels to draw text, creating a shadow effect.

g.DrawString (' Chong Pupil software Studio ', 7,font1,makerect (151,21,jpg.getwidth/1,jpg.getheight), STRFORMAT,SB1);
g.DrawString (' Chong Pupil software Studio ', 7,font1,makerect (150,20,jpg.getwidth/1,jpg.getheight), STRFORMAT,SB1);

------Set the image quality encoding parameters, save the file---------------------
Quality: = 90;
Parameters.count: = 1;
Parameters.parameter[0]. Guid: = encoderquality;
Parameters.parameter[0]. Type_:= Encoderparametervaluetypelong;
Parameters.parameter[0]. NumberOfValues: = 1;
//Set parameter values: Quality level, up to 100, image file size proportional to quality
Parameters.parameter[0]. Value: = @Quality;
Getencoderclsid (' Image/jpeg ', encoderclsid);
Bmp.save (Dname, Encoderclsid, @Parameters);

Release
SB1. Free;
Font1. Free;
Strformat.free;
Jpg. Free;
Bmp. Free;
Imageattr.free;
Watermark.free;
G.free;

End

In the online article, Tgpsolidbrush.create ($50000000); This function with the parameter is $99000000, draw the text is opaque, and in the web also did not search to draw transparent text code, once made me think to make text transparent, must first save as a picture, and then use the method of drawing watermark to realize, later thought, is not arbg a (transparency) too big, In GDI +, use arbg,$99000000 to represent a=$99, try to change the color of a to $, text transparency effect is out.

Http://www.cnblogs.com/hssbsw/archive/2012/06/03/2533088.html

Delphi to achieve suspended karaoke subtitles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.