TGPImageToBitmap TGPImage转TBitmap

2020-06-15

function TGPImageToBitmap(Image: TGPImage): TBitmap;

var

  Graphics: TGPGraphics;

  Bitmap: TBitmap;

  P: Pointer;

  W, H: Cardinal;

begin

  Bitmap := nil;

  if Assigned(Image) then

  begin

    W := Image.GetWidth;

    H := Image.GetHeight;

    if (W > 0) and (H > 0) then

    begin

      Bitmap := TBitmap.Create;

      Bitmap.PixelFormat := pf32Bit;

      Bitmap.Width := W;

      Bitmap.Height := H;

      P := Bitmap.ScanLine[H - 1];

      FillChar(P^, (W * H) shl 2, 0);

      Graphics := TGPGraphics.Create(Bitmap.Canvas.Handle);

      try

        Graphics.DrawImage(Image, 0, 0);

      finally

        Graphics.Free;

      end;

    end;

  end;

  Result := Bitmap;

end;


阅读85