Author |
Topic |
|
AlexanderNovikov7
Russia
5 Posts |
Posted - Apr 04 2017 : 09:54:13
|
Hi everybody! Does anybody know how can I add transparent bitmap to IEBitmap and how can i make transparent text on IEBitmap (without using tImageEnView)? Here my code:
iMIO.LoadFromStream(FileStream);
FileStream.Position := 0;
iMultiBitmap.ResampleAll( 0.3, rfnone );
for k := 0 to iMIO.IEMBitmap.Count - 1 do
begin
iMIO.IEMBitmap.CopyToIEBitmap(k,aieBitmap) ;
aieBitmap.AlphaChannel.CanvasCurrentAlpha := 60;
aieBitmap.Canvas.CopyRect(
Rect(0, 0, 0 + _BCodeBitMap.Width, 0 + _BCodeBitMap.Height),
_BCodeBitMap.Canvas,
Rect(0, 0, _BCodeBitMap.Width, _BCodeBitMap.Height));
iImageEnProc := TImageEnProc.CreateFromBitmap(aieBitmap);
iFont := CreateFont(90,90, 10*45, 10*45, 1000, 0, 0, 0,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH or FF_DONTCARE, 'Courier New' );
SelectObject(iImageEnProc.AttachedIEBitmap.Canvas.Handle, iFont);
SetBkMode(iImageEnProc.AttachedIEBitmap.Canvas.Handle, Transparent);
SetTextColor(iImageEnProc.AttachedIEBitmap.Canvas.Handle, clBlue);
iImageEnProc.AttachedIEBitmap.Canvas.Font.Handle:=ifont;
iImageEnProc.AttachedIEBitmap.Canvas.TextOut(0,180, 'transparent');
DeleteObject(iFont);
iMultiBitmap.SetImage(k,iImageEnProc.AttachedIEBitmap);
end;
Hope you guys understand me |
|
xequte
38611 Posts |
|
AlexanderNovikov7
Russia
5 Posts |
Posted - Apr 05 2017 : 02:01:38
|
I need a transparent text (watermark), thats why i dont use textout method. When im using textout method the text is totaly black. Maybe i need change some settings or something? And the second question is: Does anybody have idea about how to add transparent bitmap on IEMBitmap? Thank you for fast answer |
|
|
w2m
USA
1990 Posts |
Posted - Apr 05 2017 : 13:00:10
|
Have you tried Nigel's code? It works perfectly here, the text is in the correct font and color and the background of the text is transparent.
Bill Miller Adirondack Software & Graphics Email: w2m@hughes.net EBook: http://www.imageen.com/ebook/ Custom Commercial ImageEn Development |
|
|
AlexanderNovikov7
Russia
5 Posts |
Posted - Apr 05 2017 : 13:26:32
|
Bill, i've tried this code. And my result for:
aieBitmap := TIEBitmap.Create;
iMultiBitmap := TIEMultiBitmap.Create;
iMIO:=TImageEnMIO.Create(nil);
iMIO.AttachedIEMBitmap:= iMultiBitmap;
iMIO.LoadFromStream(FileStream);
FileStream.Position := 0;
iMultiBitmap.ResampleAll( 0.3, rfnone );
for k := 0 to iMIO.IEMBitmap.Count - 1 do
begin
iMIO.IEMBitmap.CopyToIEBitmap(k,aieBitmap) ;
with TImageEnProc.CreateFromBitmap(aieBitmap) do
begin
TextOut(Align_Text_Horz_Center, Align_Text_Near_Bottom, 'Me in Italy - 2015', 'Arial', 90, clRed, [fsBold]);
Free;
end;
iMultiBitmap.SetImage(k,aieBitmap); is totaly white text; for:
aieBitmap := TIEBitmap.Create;
iMultiBitmap := TIEMultiBitmap.Create;
iMIO:=TImageEnMIO.Create(nil);
iMIO.AttachedIEMBitmap:= iMultiBitmap;
iMIO.LoadFromStream(FileStream);
FileStream.Position := 0;
iMultiBitmap.ResampleAll( 0.3, rfnone );
for k := 0 to iMIO.IEMBitmap.Count - 1 do
begin
iMIO.IEMBitmap.CopyToIEBitmap(k,aieBitmap) ;
with TImageEnProc.CreateFromBitmap(aieBitmap) do
begin
TextOut(Align_Text_Horz_Center, Align_Text_Near_Bottom, 'Me in Italy - 2015', 'Arial', 90, clBlack, [fsBold]);
Free;
end;
iMultiBitmap.SetImage(k,aieBitmap); is totaly black text;
Maybe i need change some params of the bitmap? I need a semi-trasparent text (watermark)
Thank you for answering! |
|
|
w2m
USA
1990 Posts |
Posted - Apr 05 2017 : 13:33:08
|
As I pointed out in my previous message that the text was the specified color and the text background was transparent. So the function works and is developed correctly. I do not know if you have a problem with your stream because my tests involve loading from a file. What component are you streaming from to create the stream?
If you really want some more in-depth help perhaps you can post a demo that reveals the problem. Do not use third-party components in your demo and include a few images you are testing with.
Bill Miller Adirondack Software & Graphics Email: w2m@hughes.net EBook: http://www.imageen.com/ebook/ Custom Commercial ImageEn Development |
|
|
w2m
USA
1990 Posts |
Posted - Apr 05 2017 : 13:45:46
|
You can also add a transparent text layer instead of using a canvas:
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
iFilename: string;
ImageEnView: TImageEnView;
iIEMultiBitmap: TIEMultiBitmap;
iLayer: Integer;
begin
Screen.Cursor := crHourGlass;
try
iFilename := DesktopFolder + 'Plain.tif';
iIEMultiBitmap := TIEMultiBitmap.Create(nil);
try
{ Create a TImageEnView at run time to be able to use layers to create transparent text }
ImageEnView := TImageEnView.Create(nil);
try
ImageEnView.Parent := Form1;
{ Read the image into iIEMultiBitmap }
iIEMultiBitmap.Read(iFilename);
{ Interate through the frames }
for i := 0 to iIEMultiBitmap.Count - 1 do
begin
{ Copy the IEBitmap frame from iIEMultiBitmap }
iIEMultiBitmap.CopyToIEBitmap(i, ImageEnView.IEBitmap);
ImageEnView.Update;
{ Create a transparent text layer }
iLayer := ImageEnView.LayersCreateFromText('PAID', 'Arial Black', 42, clBlue, [fsBold], False, 0, 0, 0, False);
{ Center the text layer on the IEBitmap }
ImageEnView.Layers[iLayer].PosY := ImageEnView.Layers[0].PosY + ImageEnView.Layers[0].Height div 2 -
ImageEnView.Layers[iLayer].Height div 2;
ImageEnView.Layers[iLayer].PosX := ImageEnView.Layers[0].PosX + ImageEnView.Layers[0].Width div 2 -
ImageEnView.Layers[iLayer].Width div 2;
{ Merge the text layer into the IEBitmap }
ImageEnView.LayersMergeAll();
ImageEnView.Update;
{ Replace the iIEMultiBitmap frame with the new IEBitmap with the text }
iIEMultiBitmap.SetImage(i, ImageEnView.IEBitmap);
end;
iIEMultiBitmap.Update;
{ Save the new IIEMultiBitmap with the text to a file }
if not iIEMultiBitmap.Write(DesktopFolder + 'TextPlain.tif') then
MessageBox(0, 'Error saving image.', 'Error', MB_ICONWARNING or MB_OK);
finally
ImageEnView.Free;
end;
finally
iIEMultiBitmap.Free;
end;
finally
Screen.Cursor := crDefault;
end;
end; Bill Miller Adirondack Software & Graphics Email: w2m@hughes.net EBook: http://www.imageen.com/ebook/ Custom Commercial ImageEn Development |
|
|
xequte
38611 Posts |
Posted - Apr 05 2017 : 17:48:17
|
Hi Alex
What kind of images are in the TImageEnMView? Are they full color?
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
AlexanderNovikov7
Russia
5 Posts |
Posted - Apr 06 2017 : 05:53:24
|
Hi Bill, hi Nigel and hi everybody!
There is a demo project in attached file. There is one feature which I would like to pay attention: if you do the same procedure(TImageEnProc.TextOut) on the saved file then the effect will be correct. Try demo
But what kind of effect i need?! I need the result which I get if I use code like this:
iMIO.IEMBitmap.CopyToIEBitmap(k,aieBitmap) ;
i:=ImageEnView1.LayersAdd;
with TImageEnProc.CreateFromBitmap(aieBitmap) do
begin
TextOut(Align_Text_Horz_Center, Align_Text_Near_Bottom, 'Me in Italy - 2015', 'Arial', 100, clGray, [fsBold]);
Free;
end;
ImageEnView1.layers[i].Bitmap.Assign(aIEBitmap);
ImageEnView1.layers[i].Transparency:=60;
ImageEnView1.LayersMergeAll;
iMIO.IEMBitmap.SetImage(k,ImageEnView1.IEBitmap); Thank you guys for fast answering!
attach/AlexanderNovikov7/20174654614_uExample.zip 2274.26 KB |
|
|
w2m
USA
1990 Posts |
Posted - Apr 06 2017 : 09:22:55
|
When I run your demo here the input file is a 1 bit black and white image, so I do not see how you can expect that colors will work at all. A 1 bit bitmap can only handle black text. You can not add colored text to 1 bit black and white image via any means.
Why are you doing this in a thread? Why does your source file not have an extension? What file format is the source file? - I assume the source file is a tiff?
Nigel posted What kind of images are in the TImageEnMView? Are they full color?
Just for experimentation I converted each frame to 24-bit and now the red text is shown correctly. The text 'Me in Italy - 2015' is red and the background is transparent:
with TImageEnProc.CreateFromBitmap(aieBitmap) do
begin
iMIO.Params[k].BitsPerSample := 8;
iMIO.Params[k].SamplesPerPixel := 3;
ConvertTo24Bit;
TextOut(Align_Text_Horz_Center, Align_Text_Vert_Center, 'Me in Italy - 2015', 'Arial', 100, clRed, [fsBold]);
Free;
end; Your source file should have an extension. The source file must be 24 bit. I assume that after you add the text and before you save the file, it could be converted to 8 bit to reduce file size. You can not save to 1 bit black and white, however; because this file type does not support color.
Bill Miller Adirondack Software & Graphics Email: w2m@hughes.net EBook: http://www.imageen.com/ebook/ Custom Commercial ImageEn Development |
|
|
AlexanderNovikov7
Russia
5 Posts |
Posted - Apr 06 2017 : 10:57:06
|
Hi Bill!
The source file is compressed and stored on the SQL server in blob field. I don't know what extension it has, but I know that I can unzip using the (z)library (u can see this in code). If you look at the code you'll see that I store the result in the stream and then load unzip file from the stream. The source file is a compressed tiff file. I perform the procedure in the thread, because the files are very large (over 100 pages) and not to freeze the main thread I do this in a secondary thread. I think it's all about settings of the bitmap! I'll Try tomorrow and give an example. I don't need just colored text, I need the text in which it is possible to adjust the degree of transparency. I Think after converting i can draw transparent text on an alphachanel. Is it right?
Thank you for your help!!! |
|
|
xequte
38611 Posts |
Posted - Apr 06 2017 : 22:41:53
|
Hi
If they are TIFF files, then it is possible they are only monochrome so you need to promote them to full color to see the text color.
The following works:
for i := 0 to IEMView1.ImageCount - 1 do
begin
bmp := IEMView1.GetTIEBitmap( i );
with TImageEnProc.CreateFromBitmap( bmp ) do
begin
ConvertTo24Bit();
TextOut(Align_Text_Horz_Center, Align_Text_Near_Bottom, 'Me in Italy - 2015', 'Arial', 25, clRed, [fsBold], 0, False);
Free;
end;
IEMView1.ReleaseBitmap( i, True );
end;
IEMView1.Update();
Though oddly, it is failing when I set the anti-alias parameter to True. I will check that...
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
|
Topic |
|
|
|