ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Transparent TBitmap
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

bmesser

United Kingdom
234 Posts

Posted - Nov 14 2012 :  10:24:53  Show Profile  Reply
Hi

I am trying to construct a TBitmap with transparency to use as an overlay over a base layer that is in fact a map in a TImageEnView component.

I am drawing the bitmap pixel by pixel from values that I have obtained by scanning multiple rainfall radar images - checked the pixel color - assigned it a value (rainfall intensity) - added it to a 500x500 array of accumulations. So the image ends up being an accumulated rainfall 'chart' for say 12 hours rainfall.

I have attached the code below that I'm using and I thought I had all the properties set correctly:

(1) Transparent = True
(2) TransparentColor = clWhite
(3) TransparentMode = tmAuto;

but no matter how I try it always ends up as a white opaque background. Can anyone point out what I'm missing?

Bruce.


bmp:=TBitMap.Create;

bmp.PixelFormat:=pf24bit;
bmp.Transparent:=True;
bmp.TransparentColor:=ColorToRGB(clWhite);
bmp.TransparentMode:=tmAuto;
bmp.Canvas.Brush.Color:=clWhite;
bmp.SetSize(500,500);

for x:=0 to 499 do
begin
for y:=0 to 499 do
begin
if data[x,y]>64 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clRed)
else if data[x,y]>56 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clLime)
else if data[x,y]>48 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clLime)
else if data[x,y]>40 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clLime)
else if data[x,y]>32 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clLime)
else if data[x,y]>28 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clWhite)
else if data[x,y]>24 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clGreen)
else if data[x,y]>20 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clAqua)
else if data[x,y]>16 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clYellow)
else if data[x,y]>12 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clNavy)
else if data[x,y]>8 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clBlue)
else if data[x,y]>4 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clDkGray)
else if data[x,y]>2 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clGray)
else if data[x,y]>1 then
bmp.Canvas.Pixels[x,y]:=ColorToRGB(clSilver);
end;
end;

Image.LayersAdd;
Image.IO.Bitmap.Assign(bmp);
Image.Update;
end;

w2m

USA
1990 Posts

Posted - Nov 14 2012 :  10:39:56  Show Profile  Reply
Do you have ImageEnView1.IO.Params.BMP_HandleTransparency := True?

property BMP_HandleTransparency: Boolean;

Description

BMP file can have 32 bits per pixel. This property controls how interpret the extra byte in the 32 bit word.
When BMP_HandleTransparency is true the extra byte is interpreted as alpha channel, otherwise it is just discarded (ignored).
This means that when a 32-bit bitmap is displayed in ImageEn, the transparent color is not used and the image is displayed without transparency if the BMP_HandleTransparency property is False.
If the BMP_HandleTransparency property is true then the image is displayed with transparency.

Example

//BMP_HandleTransparency = true then display with transparency
ImageEnView1.IO.Params.BMP_HandleTransparency := True;
You probably have to call SetTransparentColors as well:
iRGB := ImageEnView1.IEBitmap.Pixels[0, ImageEnView1.IEBitmap.Height - 1];
ImageEnView1.Proc.SetTransparentColors(iRGB, iRGB, 0);
What is data? An array of? Explain how you fill it so I can duplicate your code here.

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

bmesser

United Kingdom
234 Posts

Posted - Nov 14 2012 :  13:08:42  Show Profile  Reply
William

I've set ImageEnView1.IO.Params.BMP_HandleTransparency to true.
I've called SetTransparentColors as well.
I've changed the bmp.PixelFormat to pf32bit instead of pf24bit.

All without any luck.

The array is just a grid of doubles to hold the accumulated values for each pixel which I then assign a color to...

TAccumlationArray = array[0..499,0..499] of double;

private
data : TAccumlationArray;

Bruce.

Go to Top of Page

w2m

USA
1990 Posts

Posted - Nov 14 2012 :  13:20:35  Show Profile  Reply
show the code used to fill data...

William Miller
Go to Top of Page

bmesser

United Kingdom
234 Posts

Posted - Nov 14 2012 :  13:23:08  Show Profile  Reply
for x:=0 to 499 do
begin
for y:=0 to 499 do
begin
col:=Layers[idx].Bitmap.Pixels_ie24RGB[x,y];

if EqualRGB(col,c1) then
begin
inc(t1);
data[x,y]:=data[x,y]+0.1;
end
else if EqualRGB(col,c2) then
begin
inc(t2);
data[x,y]:=data[x,y]+0.75;
end
else if EqualRGB(col,c3) then
begin
inc(t3);
data[x,y]:=data[x,y]+1.5;
end
else if EqualRGB(col,c4) then
begin
inc(t4);
data[x,y]:=data[x,y]+3;
end
else if EqualRGB(col,c5) then
begin
inc(t5);
data[x,y]:=data[x,y]+6;
end
else if EqualRGB(col,c6) then
begin
inc(t6);
data[x,y]:=data[x,y]+12;
end
else if EqualRGB(col,c7) then
begin
inc(t7);
data[x,y]:=data[x,y]+24;
end
else if EqualRGB(col,c8) then
begin
inc(t8);
data[x,y]:=data[x,y]+32;
end
else if not(EqualRGB(col,mask)) then // ie transparent
inc(t0);
end;
end;
Go to Top of Page

w2m

USA
1990 Posts

Posted - Nov 14 2012 :  16:41:23  Show Profile  Reply
Problem solved and response by email.

// Make the black pixels transparent
ImageEnView1.Proc.CastAlpha(0, iIEBitmap.Height-1, 0, 15);
solved the problem.

William Miller
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: