2013-11-20 88 views
-1

我有一個功能,採取android安裝應用程序與他們的圖標。該函數提取Jdrawable並將其轉換爲Jbitmap(並且爲了測試這個函數,我將這個jbitmap保存到了文件中並且一切正常),但是如果我嘗試將此jbitmap轉換爲Tbitmap,我在此行有訪問衝突:位圖轉換德爾福xe5

如果Result.Map(TMapAccess.maWrite,的BitmapData)然後

function JBitmapToBitmap(const AImage: JBitmap): TBitmap; 
var 
    ImageData: TJavaArray<Integer>; 
    BitmapData: TBitmapData; 
    Width, Height: Integer; 
begin 
    Assert(AImage <> nil); 
    Width := AImage.getWidth; 
    Height := AImage.getHeight; 
    ImageData := TJavaArray<Integer>.Create(Width * Height); 
    AImage.getPixels(ImageData, 0, Width, 0, 0, Width, Height); 
    if Result.Map(TMapAccess.maWrite, BitmapData) then <--- access violation 
    try 
    Result := TBitmap.Create(Width, Height); 
    Move(ImageData.Data^, BitmapData.Data^, Width * Height * SizeOf(Integer)); 
    finally 
    Result.Unmap(BitmapData); 
    end 
    else 
    Result := nil; 
end; 

我敢肯定的是,jBitmap沒有損壞,因爲如果我保存到文件的Jbitmap,我可以看到它好。

在此先感謝

回答

3

你應該地圖方法調用之前創建結果對象

+0

哦謝謝,這是一個愚蠢的錯誤! – user1931849