English 中文(简体)
有可能以TImage和GDI Plus播放形象,保持充分的透明度
原标题:Is it possible to open a image with TImage and GDIPlus and maintain full transparency
  • 时间:2012-04-13 15:08:19
  •  标签:
  • delphi
  • gdi+

我可以取得32幅图像,在德国国际移民发展公司加工业公司中展示,这种图像具有部分(男性)透明度,但甲型数值要么0,要么255,在两者之间没有任何价值。 我试图装载PngImage、32幅比图和ons,所有这些都会产生同样的......掩盖了透明度,但并非完全透明。

是否还有另一种方式使TImage能够以完全透明的方式展示全球DI+图象,如预期结果图像所示?

enter image description here GDI Plus After Open

enter image description here Desired Result

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;
最佳回答

你们需要做的是选择一个背景图,该图将与图象在传输时所汲取的表面混在一起。 页: 1

iStatus := GPBitmap.GetHBITMAP ( aclBlack, iHBitmap );

用途

iStatus := GPBitmap.GetHBITMAP(ColorRefToARGB(ColorToRGB(clBtnFace)), iHBitmap);

例如,如果图像出现违约的彩色形式。

At this point you already know that the image has no alpha channel, but it has been flattened using a suitable color. The Transparent.. properties of TBitmap will not help with partial transparency. If you set the Transparent property of the TBitmap, it will still be like the first image of your question when you put it on a different colored background, probably with a nicer edge color. In any case, if you 用途 it, do not forget to set the TransparentColor to clBtnFace instead of clBlack .

问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签