程序内容如下
Dim Bru As Long '刷子句柄
Dim WDC As Long 'pic1句柄
Dim picBits() As Byte
Dim picInfoD As BITMAP
Dim bytesperpixel As IntegerPrivate Sub Form_Load()
Pic2.Width = Pic1.Width
Pic2.Height = Pic1.Height
End Sub
'注: 图片框scalemode设置为pixel
Private Sub Pic1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Pic1.DrawMode = 13
If SPN = 0 Then
SPN = 1
ReDim Preserve PTS(1 To 2)
PTS(1).X = X
PTS(1).Y = Y
ElseIf SPN = 1 Then
SPN = 2
PTS(2).X = X
PTS(2).Y = Y
Else
SPN = 3
Pic1.DrawMode = 13
WDC = GetDC(Pic1.hwnd)
Bru = CreateSolidBrush(vbBlack)
ReDim Preserve PTS(1 To 3)
PTS(3).X = X
PTS(3).Y = Y
hRgn = CreatePolygonRgn(PTS(1), 3, 1)
FillRgn WDC, hRgn, Bru
DeleteObject hRgn
DeleteObject Bru
With Pic1
GetObject .Image, Len(picInfoD), picInfoD
bytesperpixel = picInfoD.bmBitsPixel \ 8
ReDim picBits(1 To picInfoD.bmWidth * picInfoD.bmHeight * bytesperpixel) GetBitmapBits .Image, UBound(picBits), picBits(1)
End With
GetBitmapBits Pic1.Image, UBound(picBits), picBits(1)
SetBitmapBits Pic2.Image, UBound(picBits), picBits(1)
End If
End Sub可是最终pic2里啥都没有
Dim Bru As Long '刷子句柄
Dim WDC As Long 'pic1句柄
Dim picBits() As Byte
Dim picInfoD As BITMAP
Dim bytesperpixel As IntegerPrivate Sub Form_Load()
Pic2.Width = Pic1.Width
Pic2.Height = Pic1.Height
End Sub
'注: 图片框scalemode设置为pixel
Private Sub Pic1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Pic1.DrawMode = 13
If SPN = 0 Then
SPN = 1
ReDim Preserve PTS(1 To 2)
PTS(1).X = X
PTS(1).Y = Y
ElseIf SPN = 1 Then
SPN = 2
PTS(2).X = X
PTS(2).Y = Y
Else
SPN = 3
Pic1.DrawMode = 13
WDC = GetDC(Pic1.hwnd)
Bru = CreateSolidBrush(vbBlack)
ReDim Preserve PTS(1 To 3)
PTS(3).X = X
PTS(3).Y = Y
hRgn = CreatePolygonRgn(PTS(1), 3, 1)
FillRgn WDC, hRgn, Bru
DeleteObject hRgn
DeleteObject Bru
With Pic1
GetObject .Image, Len(picInfoD), picInfoD
bytesperpixel = picInfoD.bmBitsPixel \ 8
ReDim picBits(1 To picInfoD.bmWidth * picInfoD.bmHeight * bytesperpixel) GetBitmapBits .Image, UBound(picBits), picBits(1)
End With
GetBitmapBits Pic1.Image, UBound(picBits), picBits(1)
SetBitmapBits Pic2.Image, UBound(picBits), picBits(1)
End If
End Sub可是最终pic2里啥都没有
解决方案 »
- 如何把最小化的窗口激活显示在屏幕前面
- 关于VsFlexgrid的列排序问题
- 无盘工作站下的UDP通信
- 怎样把flash动画加入到vb的窗体中
- 怎样捕获richtextbox的滚动条在滚动?
- 请问:用什么方法可以让SHELL(CALC.EXE)计算器永远在所有窗体之上(最好有代码)
- 字符串既有半角又有全角,字母,文字,怎么取出前几个字符?
- 关于vb api函数 openprinter()
- 请问为什么这种写法不能打开记录集?
- vb中如何用代码在excel中插入一行,我的这段代码有何错误????
- 简单的ADO问题,请求帮助
- vb 中怎么我点不出print方法?!!谢谢!例:form1.提示后面找不见print
pic1.AutoRedraw=True
pic2.AutoRedraw=True
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As LongPrivate Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Dim Bru As Long '刷子句柄
Dim WDC As Long 'pic1句柄
Dim picBits() As Byte
Dim picInfoD As BITMAP
Dim bytesperpixel As Integer
Dim PTS() As POINTAPI
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
Pic2.Width = Pic1.Width
Pic2.Height = Pic1.Height
Pic1.AutoRedraw = True
Pic2.AutoRedraw = True
End Sub
'注: 图片框scalemode设置为pixel
Private Sub Pic1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
spn = 2
Pic1.DrawMode = 13
If spn = 0 Then
spn = 1
ReDim Preserve PTS(1 To 2)
PTS(1).x = x
PTS(1).y = y
ElseIf spn = 1 Then
spn = 2
PTS(2).x = x
PTS(2).y = y
Else
Pic1.Print "sdfsdfa"
spn = 3
Pic1.DrawMode = 13
WDC = GetDC(Pic1.hwnd)
Bru = CreateSolidBrush(vbBlack)
ReDim Preserve PTS(1 To 3)
PTS(3).x = x
PTS(3).y = y
hRgn = CreatePolygonRgn(PTS(1), 3, 1)
FillRgn WDC, hRgn, Bru
DeleteObject hRgn
DeleteObject Bru
With Pic1
GetObject .Image, Len(picInfoD), picInfoD
bytesperpixel = picInfoD.bmBitsPixel \ 8
ReDim picBits(1 To picInfoD.bmWidth * picInfoD.bmHeight * bytesperpixel) GetBitmapBits .Image, UBound(picBits), picBits(1)
End With
GetBitmapBits Pic1.Image, UBound(picBits), picBits(1)
SetBitmapBits Pic2.Image, UBound(picBits), picBits(1) 'Pic2.Refresh
End If
End Sub
其次,如果你执意要使用.Image属性,那么再将autoredraw=true的同时,还需要在Pict1中载入一幅图像。
最后,如果Pic2的Autoredraw=false,那么你需要pic2.refresh另外,倒数第二条语句GetBitmapBits Pic1.Image, UBound(picBits), picBits(1)纯属多余。修改代码后,在Pic1中点击鼠标三次,使其围成一个三角形,你可以看到一个三角形,并将Pic1中的图像复制到pic2中。如果你不明白为什么要在Pic1中加入图像,那么你去找些相关的资料看一下,了解一下PictureBox控件在Autoredraw不同值时,Image、hdc等属性的关系和不同你就会理解了。
首先,我告诉你我已经设置了一个模块级变量,不设置我也不可能把源码发上来,我发的只是部分源码!
其次,我想要的是我用当前画刷画出来的三角形,而不是一幅图片而已
最后,我的pic2已经设置了artoredraw=false
另外,我想知道你是怎么判断倒数第二条语句是多余的,我用GetBitmapBits Pic1.Image, UBound(picBits), picBits(1)不仅仅是想复制图片而已,而是后续有相应的位图操作,至于是什么操作,不好意思,不告诉你!
修改代码后,在pic1中点击三次,麻烦你试一下,我可以告诉你,执行到GetBitmapBits .Image, UBound(picBits), picBits(1)时pic1里已经没有三角形了,麻烦你敬业一些亲自试试.
如果你不明白我的用意,请给我email
最后还是要谢谢你
2、请设 pic1.AutoRedraw=True