我可以使用具有部分(屏蔽)透明度的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