我想將TBitMap轉換爲KOL中的PBitMap。TBitMap到PBitMap KOL
我試過,但我得到一個黑色的畫面作爲輸出:
function TbitMapToPBitMap (bitmap : TBitMap) : PbitMap;
begin
result := NIL;
if Assigned(bitmap) then begin
result := NewBitmap(bitmap.Width, bitmap.Height);
result.Draw(bitmap.Canvas.Handle, bitmap.Width, bitmap.Height);
end;
end;
任何想法有什麼錯呢?我正在使用Delphi7。
謝謝你的幫助。
編輯:新代碼:
function TbitMapToPBitMap (const src : TBitMap; var dest : PBitMap) : Bool;
begin
result := false;
if ((Assigned(src)) and (Assigned (dest))) then begin
dest.Draw(src.Canvas.Handle, src.Width, src.Height);
result := true;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TBitMapTest : TBitMap;
PBitMapTest : PBitMap;
begin
TBitMapTest := TBitMap.Create;
TBitMapTest.LoadFromFile ('C:\test.bmp');
PBitMapTest := NewBitMap (TBitMapTest.Width, TBitMapTest.Height);
TbitMapToPBitMap (TBitMapTest, PBitMapTest);
PBitMapTest.SaveToFile ('C:\test2.bmp');
PBitMapTest.Free;
TBitMapTest.Free;
end;
關於您的編輯,您仍然將'Dest'繪製到'Source'。反之亦然。 – TLama
我不明白:/我想將TBitMap轉換爲PBitmap。所以PBitMap是目的地,TBitMap是源。 –
閱讀KOL的'TBitmap.Draw'函數所寫的內容:*繪製位圖給定的設備上下文。如果位圖是DIB ... *,那麼您將「Dest」繪製爲「Source」。 – TLama