我可以使用具有部分(屏蔽)透明度的GDIPlus在TImage中显示32位图像,但alpha值为0或255没有值之间。我已经尝试加载PngImage,32位位图和图标都产生相同的...蒙面透明度,但不是完全透明。是否可以使用TImage和GDIPlus打开图像并保持完全透明
是否有另一种方法让TImage能够显示具有完全透明度的GDI +图形,如所需结果图像所示?
GDI加开
所需的结果后
procedure TFormMain.Open1Click (Sender: TObject);
// Load a GDIPlus Bitmap into TImage
var
GPBitmap: TGPBitmap;
iHBitmap: HBITMAP;
iStatus: TStatus;
const
TRANS_COLOR = clBlack;
begin
if OpenPictureDialog1.Execute then
begin
FilePath := OpenPictureDialog1.FileName;
begin
GPBitmap := TGpBitmap.Create (FilePath);
try
iStatus := GPBitmap.GetHBITMAP (aclBlack, iHBitmap);
// As best as I can determine from the internet, the GetHBitmap which is needed to assign a GPbitmap to TImage
// does not hold an alphachannel, so loaded images alpha are either 0 or 255, but drawing with alphachannel values does work.
if iStatus = Ok then
begin
Image1.Picture.Bitmap.Handle := iHBitmap;
Image1.Picture.Bitmap.TransparentColor := Image1.Picture.Bitmap.Canvas.Pixels [ 0, Image1.Picture.Bitmap.Height - 1 ];
StatusBar1.Panels [ 0 ].Text := FileCtrl.MinimizeName (ExtractFileDir (FilePath), Canvas, 200); // Folder
StatusBar1.Panels [ 1 ].Text := FileCtrl.MinimizeName (ExtractFileName (FilePath), Canvas, 75); // Filename
StatusBar1.Panels [ 2 ].Text := 'Width: ' + IntegerToString (Image1.Picture.Bitmap.Width); // Width
StatusBar1.Panels [ 3 ].Text := 'Height: ' + IntegerToString (Image1.Picture.Bitmap.Height); // Height
StatusBar1.Panels [ 4 ].Text := BitDepthToColorString (GetPixelFormatSize (GPBitmap.GetPixelFormat)); // Bitdepth
Image1.Refresh;
end;
finally
GPBitmap.Free;
end;
end;
end;
end;
不确定如果我对TImage(不是使用GDI +渲染到您的画布)与TGPBitmap无法正常工作感到惊讶。相反,请查看这里的其他问题,以显示如何将带有透明度的Png加载到TImage中。这个问题就像是在问为什么我的Commodore 64不理解IP V6。 – 2012-04-13 15:12:29
@沃伦 - 我搜查了但没有发现任何显示如何解决这个问题。你有任何链接? TImage或HBitmap是否会导致问题? – Bill 2012-04-13 15:37:34
看到这个问题的一种方式,“TImage.Picture'的PNG支持可能被破坏。您可能安装了伪造组件集或安装了替代PNG组件集,实际上是对Delphi/VCL PNG的支持。看到这个链接:http://stackoverflow.com/questions/7163594/a-button-control-and-underlying-replacement-for-tbitmap-that-properly-handles-pn – 2012-04-13 16:39:36