如何得知图形图象表面任意一点是否透明?(200分)

  • 主题发起人 主题发起人 lxggc
  • 开始时间 开始时间
L

lxggc

Unregistered / Unconfirmed
GUEST, unregistred user!
如提。此处的图形图象包括bmp,wmf 等格式,此问题困扰本人太久,仍无良策,只好
向高手请教了。
 
bmp, wmf文件中没有透明的属性定义
 
虽然bmp, wmf文件中本身并没有透明的属性定义,但是它们在显示时是可以设置为透明的,
我要求的就是判定他们显示时某一点是否透明。
 
there are a component called coolform,
I think you will find out the answer after you check the source code of it.

 
可以判断位图某点是否为透明色;
你需要利用TBitmap的TransParent属性和TransParentColor属性进行设置,
当然还有TransParentMode属性来进行比较

procedure TForm1.Button1Click(Sender: TObject);
var
Bitmap : TBitMap;
begin
Bitmap := TBitmap.Create;
try
with Bitmap do begin
LoadFromFile('f:/图片/aimasic.bmp');
//首先显示原图
TransparentMode := tmAuto; //这是系统默认的透明色
Form1.Canvas.Draw(0,0,BitMap);
//下面是根据自己设定的透明色将位图透明处理
Transparent := True;
TransParentColor := BitMap.canvas.pixels[80,80];//透明色为该点的颜色
Form1.Canvas.Draw(500,0,BitMap); //为便于比较,显示透明处理后的位图
end;
finally
Bitmap.Free;
end;
end;

所以,你如果想知道某点是否为透明,你需要首先知道你设置的透明色。
当然,如果你没有设置透明色,那么系统在TransParentMode为tmAuto时,默认透明色
为位图最右下角的象素颜色。此时你只要判断你取的点的颜色是否与最右下角相等就
知道是否为透明色了。
OK?
 
卷起千堆雪tyn的回答是正确的,但只解决了问题的一部分,如果图形格式为 MetaFile 又如何
判断呢?
 
图形格式为MeteFile,你同样可以先将MetaFile先转换为BMP,然后再处理么。

procedure WmfToBmp(FicheroWmf,FicheroBmp:string);
var
MetaFile:TMetafile;
Bmp:TBitmap;
begin
Metafile:=TMetaFile.create;
{Create a Temporal Bitmap}
Bmp:=TBitmap.create;
{Load the Metafile}
MetaFile.LoadFromFile(FicheroWmf);
{Draw the metafile in Bitmap's canvas}
with Bmp do
begin
Height:=Metafile.Height;
Width:=Metafile.Width;
Canvas.Draw(0,0,MetaFile);
{Save the BMP}
SaveToFile(FicheroBmp);
{Free BMP}
Free;
end;
{Free Metafile}
MetaFile.Free;
end;
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
794
import
I
I
回复
0
查看
636
import
I
I
回复
0
查看
640
import
I
后退
顶部