图像翻转的问题(高手请看看,我困惑ing)

chenyanlin 2005-11-03 11:31:47
1)在窗体中添加2个picturebox控件,picture1做主容器,picture2做图像处理缓冲器,高手能帮我解析一下这个原理嘛
2)我在书上抄了一段代码,可是并没有出现书上所说的图像翻转。 代码是这样的:
Private Sub MENU_IMAGE_FLIPH_Click()
Dim X, Y, c
Picture2.Cls
Picture2.Picture = Picture1.Picture
Screen.MousePointer = 11 '将鼠标光标设为等待图像
For Y = 0 To Picture1.ScaleHeight - 1
For X = 0 To Picture1.ScaleWidth - 1
'水平翻转
c = Picture2.Point(Picture1.ScaleWidth - 1 - X, Y) '取出对应点的rgb值
Picture1.PSet (X, Y), c
DoEvents
Next X
Next Y
Screen.MousePointer = 0 ' 恢复鼠标指针
End Sub
图像并没有水平翻转,而是很慢的速度扫描图像,图像变的看不清楚了
请问高手这个是怎么回事呢???
...全文
231 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
900126 2005-11-03
  • 打赏
  • 举报
回复
关键是里面的 step 15 ,会大大提高速度,不会影响质量。
900126 2005-11-03
  • 打赏
  • 举报
回复
或者:
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
For i = 0 To Picture1.Width Step 15
For j = 0 To Picture1.Height Step 15
s = Picture1.Point(i, j)
Picture2.PSet (Picture1.Width - i, j), s
Next j
Next i
900126 2005-11-03
  • 打赏
  • 举报
回复
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
For i = 0 To 1000 Step 15
For j = 0 To 1000 Step 15
s = Picture1.Point(i, j)
Picture2.PSet (Picture1.Width - i, j), s
Next j
Next i
chenyanlin 2005-11-03
  • 打赏
  • 举报
回复
请高手给出更加高明的策略,让小弟知道山外有这么多高山
Summer006 2005-11-03
  • 打赏
  • 举报
回复
用 Point 处理图象翻转,也就是理论上可行。实际上太慢了,没意义。
========
说得是,这类教程没有实用价值,只是让初学者容易理解而已。
Summer006 2005-11-03
  • 打赏
  • 举报
回复
For Y = 0 To Picture1.ScaleHeight - 1
For X = 0 To Picture1.ScaleWidth - 1
'水平翻转
c = Picture2.Point(Picture2.ScaleWidth - 1 - X, Y)
Picture1.PSet (X, Y), c

DoEvents
Next X
Next Y
要把picture1 和2 的scalemode改为3-pixels。
fxy_2002 2005-11-03
  • 打赏
  • 举报
回复
用 Point 处理图象翻转,也就是理论上可行。实际上太慢了,没意义。

以上代码对 x,y 的坐标值没作翻转,图象当然也没有翻转。实际上是一段图象复制代码。
zhangjinzhicn 2005-11-03
  • 打赏
  • 举报
回复
www.wave12.com 的图片组件支持任意角度旋转
chenyanlin 2005-11-03
  • 打赏
  • 举报
回复
to northwolves(狼行天下) :
为什么StretchBlt这个函数没有定义呢?? 模块里面加了这个函数了呀!!!
在运行时候说StretchBlt函数没有定义
熊孩子开学喽 2005-11-03
  • 打赏
  • 举报
回复
因为书上用的是PICTURE控件的取点和画点方法,所以速度非常慢,才会变成扫描样。
其实快速翻转图片应该用PICTURE控件的PAINTPICTURE方法。
写个例程给你看一下就明白了:
新建工程,添加两个PICTURE和COMMAND按钮。

Option Explicit

Private Sub Form_Load()
Me.ScaleMode = 3
Command1.Caption = "水平"
Command2.Caption = "垂直"
Picture1.ScaleMode = 3 '单位为像素
Picture2.ScaleMode = 3
Picture2.Picture = LoadPicture("c:\test.jpg") '加载一个图片,可以改成你的文件
End Sub


Private Sub Command1_Click()
Picture1.PaintPicture Picture2.Picture, Picture1.Width, 0, -Picture1.Width
End Sub

Private Sub Command2_Click()
Picture1.PaintPicture Picture2.Picture, 0, Picture1.Height, Picture1.Width, -Picture1.Height
End Sub

运行一下就知道了
韧恒 2005-11-03
  • 打赏
  • 举报
回复
如果只想翻转图像,问题没那么复杂。只一条语句足够。
picture1中有一幅图像,将两个图片框的大小设置为相同:

Private Sub Command1_Click()
' 垂直翻转
Picture2.PaintPicture Picture1.Picture, 0, Picture1.ScaleHeight, Picture1.ScaleWidth, -Picture1.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
End Sub

Private Sub Command2_Click()
' 水平翻转
Picture2.PaintPicture Picture1.Picture, Picture2.ScaleWidth, 0, -Picture1.ScaleWidth, Picture1.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
End Sub
northwolves 2005-11-03
  • 打赏
  • 举报
回复
我以前写过类似代码,供你参考一下(http://dev.csdn.net/develop/article/37/37831.shtm)


Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020
Private WithEvents pic1 As PictureBox
Private WithEvents pic2 As PictureBox


Sub Form_Load()
Me.Move 0, 0, 10200, 4000
Set pic1 = Controls.Add("vb.picturebox", "pic1", Me)
pic1.Visible = True
pic1.Move 0, 0, 5000, 2500
Set pic2 = Controls.Add("vb.picturebox", "pic2", Me)
pic2.Visible = True
pic2.Move 5000, 0, 5000, 2500
pic1.ScaleMode = 3
pic2.ScaleMode = 3
End Sub


Sub Form_Click()
pic2.CurrentX = 0
pic2.CurrentY = 0
pic2.FontSize = 120
pic2.ForeColor = vbRed
pic2.FontName = "隶书"
pic2.Print "镜像"
StretchBlt pic1.hdc, pic2.ScaleWidth, 0, -pic2.ScaleWidth, pic2.ScaleHeight, pic2.hdc, 0, 0, pic2.ScaleWidth, pic2.ScaleHeight, SRCCOPY
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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