GDI+转换有关问题

GDI+转换问题
Delphi(Pascal) code

var
  TempBMP:TBitmap;
  gpBmp:TGPBitmap;
  g:TGPGraphics;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Interval:=33;
  ...
  //gpBmp:=TGPBitmap.Create(TempBMP.Handle,TempBMP.Palette);
  //放在这里貌似无效,在Timer1里面,gpBmp不会随着TempBMP而更新
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ... //这里在TempBMP上面画一些图形

  gpBmp:=TGPBitmap.Create(TempBMP.Handle,TempBMP.Palette);
  g.DrawImage(gpBmp,0,0);
  gpBmp.Free;
  //放在这里的话,由于不断初始化和销毁,会占用很多的CPU

  ...
end;



有没有更好的办法,使得gpBmp(或者g)随着TempBMP而更新?而我又不想在g直接画图形,因为要考虑向下兼容,无法完全抛弃GDI。

------解决方案--------------------
两者的内存数据是独立的。。互不干涉, 得手动拷贝数据才行吧
------解决方案--------------------
用gdi api直接画试试
------解决方案--------------------
可以开辟 一块内存,每次图像变换后,更新这块内存,bmp都从这个内存中加载
------解决方案--------------------
http://www.progdigy.com/files/gdiplus.zip
------解决方案--------------------
楼就是想让两个TGPBitmap对象里的图完全一样对吧?就类似于一些常用控制的Assign()方法 ,GDI+有变通实现的方法。
------解决方案--------------------
我最近在研究这一块,关键是要找到两个函数,我已经找到一个GPBmpToBmp,另一个BmpToGPBmp还没找着:
Delphi(Pascal) code
function BmpToGPBmp(bmp: TBitmap; alpha: Byte = 256): TGPBitmap;
var
  x, y: Integer;
  p0, p1: pbytearray;
  isXPIcon: boolean;
  ScanLines: array of Byte;
  W, H: integer;
  Data: TBitmapData;
  CurrentX: integer;
begin
  bmp.PixelFormat := pf32bit;
  try
    SetLength(ScanLines, Bmp.Height * Bmp.Width * 4);
    for y := 0 to bmp.Height - 1 do
    begin
      p0 := bmp.scanline[y];
      CurrentX := bmp.Width * y * 4;
      for x := 0 to bmp.Width - 1 do
      begin
        ScanLines[CurrentX + x * 4] := p0[x * 4];
        ScanLines[CurrentX + x * 4 + 1] := p0[x * 4 + 1];
        ScanLines[CurrentX + x * 4 + 2] := p0[x * 4 + 2];
        //设置Alpha
        ScanLines[CurrentX + x * 4 + 3] := alpha; // p0[x * 4 + 3];
      end;
    end;

    Result := TGPBitmap.Create(bmp.Width, bmp.Height); //(bmp.Handle, bmp.Palette); //  ;//
    W := Result.Width;
    H := Result.Height;
    Data := Result.LockBits(GpRect(0, 0, W, H), [imRead, imWrite], pf32bppARGB);
    Move(ScanLines[0], Data.Scan0^, Data.Height * Data.Stride);
    Result.UnlockBits(Data);
  finally
    SetLength(ScanLines, 0);
  end;
end;