我想实现在picturebox1中的图片中画一个圆,然后将这个圆所包含的图片在另一个picturebox中显示出来,不知怎么做?
解决方案 »
- 数据类型的小疑问
- 用vb+sql做的系统,打包后,在其他的机子上,如何不安装sql就可使用?
- 麻烦各位帮我看一下,小弟新手,搞不懂,谢谢
- 有何错误
- 谁有Janus Systems GridEX2000b 控件的注册码?请提供一份,谢谢。
- 下面这段代码实现什么功能
- 给个例子,在线等待!
- VB6,怎样播放3GP/MP4文件(100分)
- VB中直接运行一个应用程序或打开相应类型的文件(例如.exe或.html),用什么语句
- playyuer(女㊣爱):请进来看看!!上次的问题还是没有解决!再来帮帮忙!!!好不好!!!要是有高手知道,请也来看看!!!我很着急,这个问题好几天了,没有解决·!再来帮帮忙!!!
- 怎样在Formula one6.0的单元格加入图片?急急
- 请问水晶报表中运行时的右键可以屏蔽吗?
其中r是圆的半径,x1,y1是矩形的左上角坐标
顺便想问一下,可不可以实现拷贝的动画显示,也就是从picture1拷贝圆到picture2时有个动画过程
Picture2.Refresh
难点在于picturebox3背景透明而且是移动的,你可以参考一下这个程序:
http://www.applevb.com/sourcecode/Page%20Balloon%20Now%20with%20API%20timer.zip
建立类似气球的屏幕精灵的程序。气球会在屏幕上上升然后停在屏幕顶端。
看个简单的吧,比如说picture1所画的圆的半径为130(或90),而我在picture2所预留的圆的半径为100,不知可不可以使得picture1的圆按半径比例缩小(或放大)后再粘帖到picture2上
你应该根据一定的算法(如插值法等)对图象进行平滑缩放
不知您有何高见,可否指教指教?
http://www.fantasiasoft.net/Zyl910/zScale.zip
主要看看里面的算法
请问SetStretchBltMode的模式HALFTONE怎么定义,我写成:
SetStretchBltMode Picture1.HDC, STRETCH_HALFTONE
提示STRETCH_HALFTONE未定义
这个http://www.fantasiasoft.net/Zyl910/zScale.zip
做得效果很好,但很像很复杂(我水平有限)
做得效果很好,但很像很复杂(我水平有限)慢慢看,总会看明白的,不要着急:)
Private Declare Function SetGraphicsMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal iMode As Long) As Long
Private Declare Function SetWorldTransform Lib "gdi32.dll" (ByVal hdc As Long, lpXform As XFORM) As Long
Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC 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 dwRop As Long) As LongPrivate Const GM_ADVANCED As Long = 2
Private Const SRCCOPY As Long = &HCC0020Private Type XFORM
eM11 As Single
eM12 As Single
eM21 As Single
eM22 As Single
eDx As Single
eDy As Single
End Type
Private Sub Form_Click()
Dim hRet As Long, xfTemp As XFORM
hRet = SetGraphicsMode(Picture2.hdc, GM_ADVANCED)
If hRet = 0 Then MsgBox "系统不支持": Exit Sub
With xfTemp
.eDx = 0
.eDy = 0
.eM11 = 0.5
.eM12 = 0
.eM21 = 0
.eM22 = 0.5
End With
SetWorldTransform Picture2.hdc, xfTemp
BitBlt Picture2.hdc, 0, 0, Picture1.Picture.Width, Picture1.Picture.Height, Picture1.hdc, 0, 0, SRCCOPY
End Sub使用方法:放上两个PictureBox,一个Picture1,一个Picture2。给Picture1.Picture赋上一张图片。运行后点击窗体,Picture2中就会有缩小的图像。详情见:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/cordspac_57cd.asp
难点在拷贝,如果使用上面的我介绍的创建剪裁区域的方法的话比较麻烦,因为创建一个扇形的区域(特别是通过角度来创建)。你可以考虑创建一个圆形区域以及一个经过圆形的三角形区域,然后将两者通过CombineRgn合并成一个区域,然后将这个区域作为目标PictureBox的剪裁区域,然后将源图像拷贝过去。
//你可以考虑创建一个圆形区域以及一个经过圆形的三角形区域
这三角形区域怎样可以确定啊?
再设置fillcolor=0,fillstyle=solid,borderwidth=0,用pie,就可以画出实心的黑色扇形(通道)
在用异或覆盖
通道外面的象素两次异或之后复原,通道里面的是盖到黑色上面的,原样显示
pie会用吗?
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As LongPrivate Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Declare Function Pie Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As LongPrivate Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function FillPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As LongPrivate Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
'8008201859
'8008203800
Private Sub Command1_Click()
Dim rgn As Long
Dim oldrgn As Long
' rgn = CreateEllipticRgn(10, 10, 160, 160)
With Picture2
BeginPath (.hdc)
Call Pie(.hdc, 50, 50, 300, 300, 300, 175, 175, 300)
FillPath (.hdc)
EndPath (.hdc)
rgn = PathToRegion(.hdc)
End With oldrgn = SelectClipRgn(Picture2.hdc, rgn)
BitBlt Picture2.hdc, 10, 10, 150, 150, Picture1.hdc, 10, 10, SRCCOPY
Call SelectClipRgn(Picture2.hdc, oldrgn)
DeleteObject rgn
End Sub
BOOL Pie(
HDC hdc, // handle to DC
int nLeftRect, // x-coord of upper-left corner of rectangle 矩形左上角X坐标
int nTopRect, // y-coord of upper-left corner of rectangle 矩形左上角Y坐标
int nRightRect, // x-coord of lower-right corner of rectangle 矩形右上角X坐标
int nBottomRect, // y-coord of lower-right corner of rectangle 矩形右下角Y坐标
int nXRadial1, // x-coord of first radial's endpoint 扇形第一条直边端点X坐标
int nYRadial1, // y-coord of first radial's endpoint 扇形第一条直边端点Y坐标
int nXRadial2, // x-coord of second radial's endpoint 扇形第二条直边端点X坐标
int nYRadial2 // y-coord of second radial's endpoint 扇形第二条直边端点Y坐标
);
以上是我的理解,不知有错没有,请指正。
我现在想做的是,在form1上的picture1截取一个圆,粘贴到form2上的picture2并进行相应的放大或缩小(已经实现了),form2上放置一按钮,单击就截取picture2上圆的30-60度的扇形,粘贴到form3上的picture3的中心位置,不知道这样做有没有问题
Dim oldrgn As Long
x0 = Fans.PicBox.ScaleWidth / 2
y0 = Fans.PicBox.ScaleHeight / 2
r = 150
x = r * Math.Cos(30 * PI / 180) + x0
y = r * Math.Cos(30 * PI / 180) + y0
With Fans.PicBox
BeginPath (.hdc)
Call Pie(.hdc, x0, y, x, y0, r * Math.Cos(30 * PI / 180), r * Math.Cos(60 * PI / 180), r * Math.Cos(60 * PI / 180), r * Math.Cos(30 * PI / 180))
FillPath (.hdc)
EndPath (.hdc)
rgn = PathToRegion(.hdc)
End With
oldrgn = SelectClipRgn(Fans.PicBox.hdc, rgn)
BitBlt Fans.PicBox.hdc, x0, y, 2 * r, 2 * r, Clip.PicBox.hdc, Clip.PicBox.ScaleWidth / 2 - r, Clip.PicBox.ScaleHeight / 2 - r, SRCCOPY
Call SelectClipRgn(Fans.PicBox.hdc, oldrgn)
DeleteObject rgn
Fans.Show vbModal
Private Declare Function Pie Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As LongPrivate Sub Picture2_Click()
Picture2.FillStyle = vbSolid
Picture2.FillColor = 0
Picture2.DrawStyle = vbTransparent
Picture2.PaintPicture Picture1.Picture, 0, 0, , , , , , , vbSrcInvert
Pie Picture2.hdc, 50, 50, 150, 150, 150, 50, 50, 50
Picture2.PaintPicture Picture1.Picture, 0, 0, , , , , , , vbSrcInvert
End Sub
此话怎讲?
可能我的理解有错,想问一下在使用pie时,
int nLeftRect, // x-coord of upper-left corner of rectangle 矩形左上角X坐标
中的矩形是指包含扇形的矩形还是包含圆形的矩形?我想我的坐标可能定错了。
你的代码闪烁的原因不是wm_paint,而是因为你执行了两次Invert Copy。你可以创建一个后台的PictureBox,然后将这两次拷贝放到这个里面执行。然后将最后的结果拷贝到目标图像上面。
我以前测试时picture2.autoredraw=true,所以他一直没闪。
刚才设picture2.autoredraw=false,才看到了他会闪。
其实你说的后台的PictureBox,就相当于picture2.hdc,
前台的PictureBox,就相当与getdc(picture2.hwnd).咱们的意思是一样的,只不过我将一些杂碎事交给vb去处理。
我现在想做的是,在form1上的picture1截取一个圆,粘贴到form2上的picture2并进行相应的放大或缩小(已经实现了),form2上放置一按钮,单击就截取picture2上圆的30-60度的扇形,粘贴到form3上的picture3的中心位置。
我发现这样做出来的picture2.picture是没有内容的,而picture2.image才有内容。还有想问一下的就是扇形的圆心坐标是在什么地方确定的?
可能是我没把问题说清楚.
现在情况是这样的:在form1上有picture1,当用鼠标在picture1上画完一个圆后,show出form2,form2上有picture2,然后将picture1上的圆形区域粘贴到picture2上,在form2上有一排按钮,分别是“0-30”,“30-60”,“60-90”,.....,“330-360”,代表的是 0度到30度,30度到60度,...,330度到360度,当点击其中的按钮时,就从picture2上截取相应度数区间的扇形并show出form3,将扇形粘贴到form3上的picture3.
现在的问题是:(1)扇形截取出来粘贴到form3的picture3上时不但会有扇形,而且会连屏幕也一起截取了,也就是picture3的底图是屏幕的截屏,然后扇形粘贴在截屏上;(2)当截取完之后,用鼠标将窗体拖动进入屏幕的边界再拉出来时,picturebox的图形会变得乱七八糟。
不知哪位高人可以指点一二?谢谢
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As LongPrivate Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Declare Function Pie Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As LongPrivate Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function FillPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As LongPrivate Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
'8008201859
'8008203800Private Type POINTAPI
x As Long
y As Long
End TypePrivate Function getCenter(x1 As Long, y1 As Long, x2 As Long, y2 As Long) As POINTAPI
Dim p As POINTAPI
p.x = (x1 + x2) / 2
p.y = (y1 + y2) / 2
getCenter = p
End FunctionPrivate Function getEndPoint(center As POINTAPI, l As Long, a As Integer) As POINTAPI
Dim p As POINTAPI
p.x = center.x + Round(l * Cos(a * (3.14 / 180)))
p.y = center.y - Round(l * Sin(a * (3.14 / 180)))
getEndPoint = p
End FunctionPrivate Sub Command1_Click()
Dim rgn As Long
Dim oldrgn As Long
Dim cent As POINTAPI
Dim e1 As POINTAPI
Dim e2 As POINTAPI
cent = getCenter(50, 50, 300, 300)
e1 = getEndPoint(cent, 125, 30)
e2 = getEndPoint(cent, 125, 60)
With Picture2
BeginPath (.hdc)
Call Pie(.hdc, 50, 50, 300, 300, e1.x, e1.y, e2.x, e2.y)
FillPath (.hdc)
EndPath (.hdc)
rgn = PathToRegion(.hdc)
End With oldrgn = SelectClipRgn(Picture2.hdc, rgn)
BitBlt Picture2.hdc, 50, 50, 250, 250, Picture1.hdc, 10, 10, SRCCOPY
Call SelectClipRgn(Picture2.hdc, oldrgn)
DeleteObject rgn
End Sub