调整图像大小并保存输出

问题描述:

我在这里看到很多有关调整图像大小的问题/解答。调整图像大小并保存输出

但我无法找到适合我的情况的正确方法。

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/ –

感谢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 –