| 发表于:2007-05-14 23:18:029楼 得分:0 |
扭转其实就是旋转,那部分代码的算法是在两幅图像上各点取两个点获得坐标值,然后计算斜率,再反求出角度,这样就可以根据两个角度的差值,用plgblt实现了。下边是扭转的代码(求角度那段的省略): private sub rotate(byref picdesthdc as long, xpos as long, ypos as long, _ byval angle as long, _ byref picsrchdc as long, srcxoffset as long, srcyoffset as_ long, byval srcwidth as long, byval srcheight as long) dim points(3) as points2d dim defpoints(3) as points2d dim thets as single, thetc as single dim ret as long points(0).x = -srcwidth * 0.5 points(0).y = -srcheight * 0.5 points(1).x = points(0).x + srcwidth points(1).y = points(0).y points(2).x = points(0).x points(2).y = points(0).y + srcheight thets = sin(angle * notpi) 'notpi = 3.14159265238 / 180 thetc = cos(angle * notpi) defpoints(0).x = (points(0).x * thetc - points(0).y * thets) + xpos defpoints(0).y = (points(0).x * thets + points(0).y * thetc) + ypos defpoints(1).x = (points(1).x * thetc - points(1).y * thets) + xpos defpoints(1).y = (points(1).x * thets + points(1).y * thetc) + ypos defpoints(2).x = (points(2).x * thetc - points(2).y * thets) + xpos defpoints(2).y = (points(2).x * thets + points(2).y * thetc) + ypos plgblt picdesthdc, defpoints(0), picsrchdc, srcxoffset, srcyoffset, srcwidth, srcheight, 0, 0, 0 end sub private sub command7_click() dim g, h, k as double g = atn((f1 - b1) / (e1 - a1)) h = atn((f2 - b2) / (e2 - a2)) '(a1,b1),(a2,b2),(e1,f1),(e2,f2)是所点的参考点坐标 k = h - g rotate picture4.hdc, picture4.scalewidth / 2, picture4.scaleheight / 2, -180 * k / pi, picture2.hdc, 0, 0, picture2.scalewidth, picture2.scaleheight 'pi = 3.14159265238 set picture4.picture = picture4.image end sub 我的程序的处理流程是这样的:打开两幅图像(在两个picturebox内显示)---在两幅图上各点3个参考点---处理拉压---处理旋转---处理平移。 想要的效果是每处理完一种变形,新生成的图像在已有的一个picturebox里显示(原有图像被覆盖),然后处理下一种变形,新生成的图像再在该picturebox里显示,如此循环直到三种变形都处理完。然而这个目前还无法实现,只能借助于第3个picturebox,感觉很麻烦。 | | |
|