2017-08-28 59 views
0

我在這裏看到很多有關調整圖像大小的問題/解答。調整圖像大小並保存輸出

但我無法找到適合我的情況的正確方法。

In this post,它只適用於當你想從一個大的小圖像。

但是,如果您有24x24尺寸的圖片,並且您想將其尺寸調整爲256x256尺寸,則procedure將失敗,並且會給您帶來扭曲的圖片。

下面的代碼是我試圖理清我的問題

Graph := TBitmap.Create; 
    try // After loading a .bmp file to Image1 with 48x48 dimension 
    Graph.Assign(Image1.Picture.Bitmap); 
    Graph.Canvas.StretchDraw(Rect(0, 0, 255, 255), Graph); 
    Graph.SetSize(255,255); 
    Graph.SaveToFile('Location\Resault.bmp'); 
    finally 
    Graph.Free; 
    end; 

原始圖像:

enter image description here

結果(白色廣場上左上方的黑色部分) :

enter image description here

我們如何將圖片加載到TImage並轉換/調整大小並保存更改?

+2

使用臨時位圖255x255和StretchDraw小的一個。如果你願意的話,可以返回到'圖表'。不要期望在將小圖像調整爲大圖像時看到很好的效果。 – kobik

+0

@kobik感謝您的評論,我會試試 – Sami

+0

或者@Sami http://chrislema.com/how-to-resize-images-to-make-them-larger-without-losing-quality/ –

回答

2

感謝kobik的評論,它很有用。

var Graph : TBitmap; Conv : TBitmap; 
begin 

     Graph := TBitmap.Create; 
     try 
     Graph.Assign(Image1.Picture.Bitmap); 
     Conv := TBitmap.Create; 
     try 
      Conv.SetSize(255,255); 
      Conv.Canvas.StretchDraw(Rect(0, 0, 255, 255), Graph); 
      Conv.SaveToFile('Location\Resault.bmp'); 
     finally 
      Conv.Free; 
     end; 

     finally 
     Graph.Free; 
     end; 

end; 
+1

@kobik完成,謝謝;) – Sami

+1

在這段代碼中,你可以刪除Graph變量並直接使用Image1.Picture.Bitmap –

+2

你的意思是256當你說255 –

相關問題