关于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;
...全文
210 4 打赏 收藏 转发到动态 举报
写回复
用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一样.. 没看懂啥意思哦
class CSBitmap //Bitmap类,特点紧约型数据结构,GetPixel效率,放弃调色板,自动支持4种色深,特有的12位颜色更接近人眼可识别颜色数目;有多种缩放,色深转换,拷贝,剪切,和hBitmap转换,显示等功能;支持串行化。支持1,12,24,32位位图,对应适用于所有函数,相比于HBitmap和CSBitmap对象要简单,可直接操作数据区;同时可用于1,4,8,12,16,24,32位二维数列的储存,部分基本函数(GetPixel,SetPixel)支持; { public: CSBitmap(void); ~CSBitmap(void); unsigned int Width; //Bitmap的宽 unsigned int Height; //Bitmap的 DWORD BitSize; //Bitmap的数据区大小(字节) BYTE* pBitData; //Bitmap的数据区指针 unsigned int BitCount; //Bitmap的色深 bool SetAttribute(unsigned int mWidth=NULL, unsigned int mHeight=NULL, unsigned int mBitCount=NULL); //设置Bitmap的属性,Bitmap会被清除 mWidth Bitmap的宽度,为NULL则不改变 mHeight Bitmap的度,为NULL则不改变 mBitCount Bitmap的色深,为NULL则不改变 bool ImportBits(BYTE* lpBits, int mBitSize=NULL); //拷贝Bits数据进对象数据区 lpBits 拷贝数据的指针 mBitSize 拷贝数据的字节数 COLORREF GetPixel(unsigned int x, unsigned int y); //获得某点的原始数值,当为12,24,32位数时,则为RGB值 X,y 需要获取点的坐标 bool SetPixel(unsigned int x, unsigned int y, COLORREF clr); //获得某点的原始数值,当为12,24,32位数时,则为RGB值 X,y 需要设置点的坐标 bool StretchDIB(CSBitmap* DestBmp, unsigned int mWidth, unsigned int mHeight, unsigned int mFlag=0); //缩放 DestBmp用于获取缩放后图片的指针 mWidth, mHeight缩放后大小 mFlag缩放算法 取值 算法 缩小 放大 0 逆向寻点算法 效率质量一般 效率质量中 1 双线性补点 效率低,质量一般 效率低,质量 2 平均值算法 效率低,质量好 效率质量差 static BYTE GetRValue12(COLORREF Clr12Bit); static BYTE GetGValue12(COLORREF Clr12Bit); static BYTE GetBValue12(COLORREF Clr12Bit); //用于12位图的获取RGB分量,24位图,32位图的COLOR分离请用GDI的GetPixel() Clr12Bit 对12位图GetPixel获得的原始值 static COLORREF RGB12(BYTE R, BYTE G, BYTE B); //用于12位图的RGB合成,24位图,32位图的COLOR合成请用GDI的RGB() static COLORREF Color24To1(COLORREF Color24); //24位色深COLORREF转1位色深(黑白)值 static COLORREF Color24To12(COLORREF Color24); //24位色深COLORREF转12位色深值 static COLORREF Color1To24(COLORREF Color2); //1位色深COLORREF转24位,32位色深(黑白)值 static COLORREF Color12To24(COLORREF Color12); //12位色深COLORREF转24位,32位色深(黑白)值 bool ConvertTo1Bit(CSBitmap* DestBmp); //12,24,36位图片转换成1位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool ConvertTo12Bit(CSBitmap* DestBmp); //1,24,36位图片转换成12位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool ConvertTo24Bit(CSBitmap* DestBmp); //1,12,36位图片转换成24位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool FromHandle(HBITMAP hBitmap); //从HBITMAP中获得CSBitmap对象 bool CopyPaste(CSBitmap* DestBmp, unsigned int x, unsigned int y); //复制本CSBitmap至另一DestBmp的指定位置 DestBmp 目标,对象 X,y复制后图片左上角位置 bool PaintDIB(CDC* dcDest, int x,int y,unsigned int mWidth, unsigned int mHeight); //把本图片显示至CDC对象上,支持1,12,24,26位图 dcDest 目标dc(兼容DC) x,y 拷贝到dc上的位置 mWidth,mHeight拷贝后的大小 const CSBitmap& operator=(const CSBitmap &SBmp); }; //重载了 = 赋值操作符

5,392

社区成员

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

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