调整图像大小并保存输出 [英] Resize images and save output

查看:121
本文介绍了调整图像大小并保存输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SO上看到有关调整图像大小的许多问题/答案。



但是我找不到适合我情况的正确问题。





结果(白色正方形,黑色部分在左上方):





如何将图像加载到 TImage 并转换/调整大小并保存更改?

解决方案

感谢 kobik 以发表评论,这很有用。

  var Graph:TBitmap;转换:TBitmap; 
开始

图:= TBitmap.Create;
试试
Graph.Assign(Image1.Picture.Bitmap);
转换:= TBitmap.Create;
试试
Conv.SetSize(255,255);
Conv.Canvas.StretchDraw(Rect(0,0,255,255),Graph);
Conv.SaveToFile(’Location\Resault.bmp’);
最终
转换免费;
结尾;

最终
图。
结尾;

结尾;


I see many questions/Answers about resizing images here on SO.

But I can't find the correct one that fit my case.

In this post, it works only when you want to have a small image from a big one.

However if you have a picture with 24x24 dimension and you want to resize it to 256x256 dimension, the procedure will fail and gives you a distorted picture.

The code below is my attempt to sort out my issue

  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;

The original image:

The result (the white square with the black part on the upper left):

How can we load an image to a TImage and convert/resize it and save changes?

解决方案

Thanks to kobik for the comment, it was useful.

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;

这篇关于调整图像大小并保存输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆