Author |
Topic  |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Nov 23 2013 : 03:27:18
|
Hi
I have a tiling issue that I've been whittling away at for some weeks. I've worked around most of the problems that I've encountered except this one:
I can't see how to stitch transparent PNG images that I've downloaded using a TImageEnView component and then added them to a TIEBitMap.
The stitching process works perfectly, but I lose the transparency that the image I downloaded had. How can I build a bitmap and maintain the transparency?
I suppose the answer lies in the function RenderToTIEBitmapEx and have tried multiple variations!
I assume this would be a problem if I was trying to stitch transparent PNG images that I had local copies of and not downloading from the internet.
Here's some pseudo code:
var
iebmp : TIEBitMap;
begin
for col:=1 to 4 do
begin
for row:=1 to 4 do
begin
...
ImageEnView1.IO.LoadFromURL(url);
ImageEnView1.IEBitmap.RenderToTIEBitmapEx(iebmp,xpos,ypos,256,256,0,0,256,256,255,rfHermite);
end;
end;
ImageEnView.IEBitmap.Assign(iebmp);
ImageEnView.IO.SaveToFilePNG(path);
Bruce. |
|
w2m
   
USA
1990 Posts |
Posted - Nov 23 2013 : 11:33:59
|
Dest.PixelFormat must be ie24RGB so that is why you loose transparency. You probably will have to tile the images manually in code without using RenderToTIEBitmapEx.
William Miller |
 |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Nov 23 2013 : 12:20:41
|
Bill
Sorry, I over simplified the pseudo code that I attached, and I do set the PixelFormat property of the ieBitMap to ie24RGB!
You might be right and I may have to do it in code without using the RenderToTIEBitmapEx method, but that would probably mean that I would have to save each tile as I accessed them, and there could be as many as 36 or more tiles in the larger maps, where as at the moment, I don't save any tiles just render them to a single bitmap and save it when I'm done.
Bruce. |
 |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Nov 23 2013 : 12:45:25
|
Bill
I've just come across MergeWithAlpha would this work perhaps?
It's past the 6 PM watershed at home so the PC's are shut down otherwise I'd have a look.
Bruce. |
 |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Nov 24 2013 : 03:19:18
|
Hi
I've now tried to do the stitching of the tiles using this:
ImageEnView.IEBitmap.RenderToCanvasWithAlpha(iebmp.Canvas,xpos,ypos,256,256,0,0,256,256);
rather than this:
ImageEnView1.IEBitmap.RenderToTIEBitmapEx(iebmp,xpos,ypos,256,256,0,0,256,256,255,rfHermite);
It worked, but I still didn't manage to preserve the alpha transparency that the ImageEnView1 component has, so I guess I am still missing something, and continue looking for a solution.
Bruce.
|
 |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Nov 24 2013 : 04:03:38
|
Hi
I have now tried to create a 3x3 image from 9 separate PNG files with transparency, and although the stitching works fine have still failed to preserve the transparency either with:
ImageEnView.IEBitmap.RenderToCanvasWithAlpha(iebmp.Canvas,xpos,ypos,256,256,0,0,256,256);
or
ImageEnView1.IEBitmap.RenderToTIEBitmapEx(iebmp,xpos,ypos,256,256,0,0,256,256,255,rfHermite);
I have included the stitching code that I am using. I can't believe this can't, or hasn't been done using ImageEN, especially in these days of GIS and tiled web services which require either cutting up, or sticking back together. To be honest the stitching part works fine, all I want to do is to preserve the transparency when I do it.
procedure TfmMain.CreateTransparentTiledImage;
var
col : integer;
row : integer;
xpos : integer;
ypos : integer;
iebmp : TIEBitMap;
path : string;
img : TImageEnView;
toprow : integer;
botrow : integer;
leftcol : integer;
rightcol : integer;
nrows : integer;
ncols : integer;
black : integer;
begin
Screen.Cursor:=crHourGlass;
try
img:=TImageEnView.Create(nil);
try
iebmp:=TIEBitMap.Create;
try
toprow :=9;
botrow :=11;
leftcol :=14;
rightcol :=16;
ncols:=(rightcol-leftcol)+1;
nrows:=(botrow-toprow)+1;
iebmp.Width:=256*ncols;
iebmp.Height:=256*nrows;
iebmp.PixelFormat:=ie24RGB;
ypos:=0;
for row:=toprow to botrow do
begin
xpos:=0;
for col:=leftcol to rightcol do
begin
img.IO.LoadFromFilePNG(Format('%stiles\%2.2d%2.2d.png',[GetExePath,Col,Row]));
// img.IEBitmap.RenderToCanvasWithAlpha(iebmp.Canvas,xpos,ypos,256,256,0,0,256,256);
img.IEBitmap.RenderToTIEBitmapEx(iebmp,xpos,ypos,256,256,0,0,256,256,255,rfNone);
// img.IEBitmap.RenderToTIEBitmapEx(iebmp.AlphaChannel,xpos,ypos,256,256,0,0,256,256,255,rfNone);
inc(xpos,256);
end;
inc(ypos,256);
end;
img.IEBitmap.Assign(iebmp);
img.IO.SaveToFilePNG(Format('%stiles\test.png',[GetExePath]));
finally
iebmp.free;
end;
finally
img.Free;
end;
finally
Screen.Cursor:=crDefault;
end;
end; |
 |
|
w2m
   
USA
1990 Posts |
Posted - Nov 24 2013 : 07:45:19
|
The problem is caused by RenderToTIEBitmapEx which outputs 24bit, regardless what you do before the call or in the call. I think you have to draw the bitmaps to a 32-bit basebitmap with alphachannel.
I just tested this with 32-bit png with alphachannel and all the images are transparent:
procedure TTileThread.UpdateImage;
{ Draw Transparent 32-bit IEBitmap to ImageEnView }
begin
Form1.ImageEnView1.IEBitmap.Canvas.Draw(X, Y, AIEBitmap.VclBitmap);
Form1.ImageEnView1.Update;
end; I have a small demo that tiles the images in a thread. Email me if you would like to test the demo with your maps.
William Miller Adirondack Software & Graphics Email: w2m@frontiernet.net EBook: http://www.imageen.com/ebook/ Apprehend: http://www.frontiernet.net/~w2m/index.html |
 |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Nov 24 2013 : 08:29:35
|
Bill
OK, I can create a 32bit BMP.
I can then copy in the transparent image pixel by pixel from the ImageEnView component (or should I do the by using scanline?). I'm not sure however how I would copy the transparency into the bitmap?
Or should I fill the base bitmap with transparency when I create it, then fill in the pixels that aren't set transparent?
I just feel that there must be some helper functions to make this process a little bit easier.
Any advice would be appreciated.
Bruce. |
 |
|
w2m
   
USA
1990 Posts |
Posted - Nov 24 2013 : 09:03:41
|
There are lots of helper functions in iexHelperFunctions for loading and creating the thumbnails.
You do not have to copy pixel by pixel or with scanline.. Just use the canvas.
To make the png transparent:
ImageEnView1.IO.Params.BitsPerSample := 8;
ImageEnView1.IO.Params.SamplesPerPixel := 4;
iRGB := ImageEnView1.IEBitmap.Pixels[0, ImageEnView.IEBitmap.Height - 1];
ImageEnView1.Proc.SetTransparentColors(iRGB, iRGB, 0);
iTransparentColor := TRGB2TColor(iRGB);
ImageEnView1.IO.Params.PNG_Background :=
TColor2TRGB(iTransparentColor); Since you have been trying to do this for so long I suggest you try to tile the images in a simple demo that uses local files. Once you get the tiling like to want then adapt it to your application that gets the images from a url.
My demo is only 390 lines long.
William Miller |
 |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Nov 24 2013 : 10:53:02
|
Bill
I got your demo fine!
I finally got it working using two ImageEnView components just like you did in your demo!
I ditched the TIEBitmap object and just copied between the two components using the trick with the line:
ImageEnView1.IEBitmap.Canvas.Draw(xpos,ypos,ImageEnView2.IEBitmap.VclBitmap);
It also works fine from images obtained using .LoadFromUrl - so that’s even better. Thanks a lot – I’ll rest a bit easier tonight.
Bruce.
|
 |
|
ali3tareh
Iran
3 Posts |
Posted - Oct 24 2015 : 16:40:42
|
Hello Bruce; I want to use tile google image map in my project from local files and I use ImageEn. would you please help and send me some source file and demo to know how to use it. thank you in advance and have a god day. yours habib mnb1353@yahoo.com |
 |
|
bmesser
  
United Kingdom
234 Posts |
Posted - Oct 25 2015 : 12:10:39
|
Why don't you use the examples that are available in SlippyMap in ImageEN?
If I want to use Google Maps I use the TMS component. |
 |
|
|
Topic  |
|
|
|