如何无失真地缩放和保存图象
编号:QA002983
建立日期: 2000年5月29日 最后修改日期:2003年8月15日
所属类别:
Q
xu long:
操作系统:Pwin98
编程工具:Vb6
问题:我用object.PaintPicture picture, x1, y1, width1, height1, x2, y2, width2, height2, opcode语句将pic1中所画的图形缩小复制到pic2中,pic1和pic2的长宽比都是4:3,然后将pic2中的所复制的图形用SavePicture Picture2.Picture来保存,可保存的图片出现了严重的失真,如何解决?
水平: 刚入门
A回答:
你可以使用PictureClip控件来放置图像。下面的范例可以将PictureClip对象上的图像缩放拷贝到PictureBox对象并实现无失真的保存。
Dim SaveMode As Integer
' Save the current ScaleMode for the picture box.
SaveMode = Picture1.ScaleMode
' Get X and Y coordinates of the clipping region.
PicClip1.ClipX = 0 'Val(Text1.Text)
PicClip1.ClipY = 0 'Val(Text2.Text)
' Set the area of the clipping region (in pixels).
PicClip1.ClipHeight = PicClip1.Height
PicClip1.ClipWidth = PicClip1.Width
' Set the picture box ScaleMode to pixels.
Picture1.ScaleMode = 3
' Set the destination area to fill the picture box.
PicClip1.StretchX = Picture1.ScaleWidth
PicClip1.StretchY = Picture1.ScaleHeight
' Assign the clipped bitmap to the picture box.
Picture1.Picture = PicClip1.Clip
' Reset the ScaleMode of the picture box.
Picture1.ScaleMode = SaveMode
'SavePicture PicClip1.Picture, "c:\b.jpg"
Picture1.Picture.Render Picture1.hDC, 0, 0, 20, 20, 10, 10, 20, 20, ByVal 0
SavePicture Picture1, "c:\a.bmp"
其中PicClip1是PictureClip对象,而Picture1是Picture对象。
http://www.applevb.com/
zyl910的意见:
使用插值算法:http://www.csdn.net/Develop/read_article.asp?id=15656
代码:http://www.fantasiasoft.net/Zyl910/zScale.zip
速度测试:
┃ 640*480┃最邻近插值│StretchBlt│双线内插值│三次卷积法┃
┃我的程序┃ 0.219 │ 0.380 │ 0.799 │ 3.037 ┃
┃内嵌汇编┃ × │ × │ 1.286 │ × ┃
┃VC的例子┃ 1.190 │ × │ 3.790 │ 9.795 ┃
此问题由Chen回答。
附加关键字:编程, 源程序, programming, source code, Visual Basic, VB, 图形、图象, picture, graph, image, draw。
| |
|
|
| |
|
|