关于GDI+--------------高质量缩小图片的问题

cowbo2 2014-02-18 11:38:04
为什么我的出错?我装的是Delphi 2010的版本,打开控件的DEMO是OK的,证明安装上没问题的.

但为什么我的代码在DrawImage时出错,提示太多的参数?

路过的大虾帮看下...谢.



procedure TForm1.SpeedButton1Click(Sender: TObject);
const Path1 = 'C:\1.bmp';
Path2 = 'C:\2.bmp';
var
Img1, Img2: IGPImage;
Graphics1: IGPGraphics;
begin
{ 打开原图片 }
Img1 := TGPImage.Create(Path1);

{ 建一个新图片,假如是缩小一倍 }
Img2 := TGPBitmap.Create(Img1.Width div 2, Img1.Height div 2,
PixelFormat32bppARGB);

{ 获取新图片的绘图表面 }
Graphics1 := TGPGraphics.Create(Img2);

{ 配置 缩放质量为最高质量 }
Graphics1.InterpolationMode := InterpolationModeHighQualityBicubic;

{ 画过来 }
Graphics1.DrawImage(Img1, 0, 0, Img2.Width, Img2.Height, 0, 0, Img1.Width,Img1.Height,UnitPixel);
{ 保存 }
Img2.Save(Path2);

end;


//以下点击DrawImage后显示的GDIPlus下的全部该名的引用
function DrawImageF(image: IGPImage; const point: TGPPointF) : TGPGraphics; overload;
function DrawImageF(image: IGPImage; x, y: Single) : TGPGraphics; overload;
function DrawImageF(image: IGPImage; const rect: TGPRectF) : TGPGraphics; overload;
function DrawImageF(image: IGPImage; x, y, width, height: Single) : TGPGraphics; overload;
function DrawImage(image: IGPImage; const point: TGPPoint) : TGPGraphics; overload;
function DrawImage(image: IGPImage; x, y: Integer) : TGPGraphics; overload;
function DrawImage(image: IGPImage; const rect: TGPRect) : TGPGraphics; overload;
function DrawImage(image: IGPImage; x, y, width, height: Integer) : TGPGraphics; overload;

function DrawImageF(image: IGPImage; const point: TGPPointF; Opacity : Single ) : TGPGraphics; overload;
function DrawImageF(image: IGPImage; x, y: Single; Opacity : Single ) : TGPGraphics; overload;
function DrawImageF(image: IGPImage; const rect: TGPRectF; Opacity : Single ) : TGPGraphics; overload;
function DrawImageF(image: IGPImage; x, y, width, height: Single; Opacity : Single ) : TGPGraphics; overload;
function DrawImage(image: IGPImage; const point: TGPPoint; Opacity : Single ) : TGPGraphics; overload;
function DrawImage(image: IGPImage; x, y: Integer; Opacity : Single ) : TGPGraphics; overload;
function DrawImage(image: IGPImage; const rect: TGPRect; Opacity : Single ) : TGPGraphics; overload;
function DrawImage(image: IGPImage; x, y, width, height: Integer; Opacity : Single ) : TGPGraphics; overload;
...全文
248 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cowbo2 2014-02-19
  • 打赏
  • 举报
回复
我知道了 改成: Graphics1.DrawImage(Img1, 0, 0, Img2.Width, Img2.Height); 就可以了,但GDI不能同时操作一个文件, 也就是不能Path1和Path2一样.. 有没办法
sololie 2014-02-19
  • 打赏
  • 举报
回复
不过再想想也不对,图像被加载到内存中后就立即关闭文件占用了,不会有冲突
sololie 2014-02-19
  • 打赏
  • 举报
回复
俺好像明白你的意思了,你是想把 C:\1.bmp 缩放一倍后保存回 C:\1.bmp ? 如果是这样,你不能保存是因为你打开了 C:\1.bmp 还没关闭,因为用的是接口类型, 你不显示地FREE它就只能等SpeedButton1Click函数返回后才会自动FREE 你显示地释放 IMG1 后,再保存就可以了 .... Img1:=nil; // 显示释放Img1 Img2.Save(Path1); // 然后保存回原图中
sololie 2014-02-19
  • 打赏
  • 举报
回复
但GDI不能同时操作一个文件,也就是不能Path1和Path2一样.. 没看懂啥意思哦

5,927

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧