复制图片

cxy5636917 2015-01-07 10:56:14

接上个帖子:http://bbs.csdn.net/topics/390964203?page=1#post-398764714


问题是如何将picture2内显示的裁剪后的图形复制到picture3内,与picture3的源图片合为一体,进行保存为图片。


8楼的最后一张图片看起来是裁剪后的图片是显示在picture3内,实际是显示在picture2内。

现在我把picture2的图形转移到picture3内时,转移的却还是picture1内没裁剪以前的图片。


难道SetWindowRgn 函数只能是用来观看效果的? 不能用来保存裁剪后的图片?


为了大家方便调试,我把源码全部放出,picture1装入一个需要裁剪的图片,picture2 显示裁剪后的图片,picture3装入一个背景图片。picture2放在picture3上面,是上下层的关系,不要放入picture3内。

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function GetRgnBox Lib "gdi32" (ByVal hRgn As Long, lpRect As Rect) As Long
Private Declare Function GetClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long

Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Dim n As Integer
Dim ap() As POINTAPI



Private Sub Command1_Click()

Dim hRgn As Long

With Picture1

hRgn = CreatePolygonRgn(ap(0), n, 1)
SetWindowRgn .hwnd, hRgn, True '将图片框Pic裁剪为多边形
SelectClipRgn .hdc, hRgn

End With

hRgn = CreatePolygonRgn(ap(0), n, 1)
SetWindowRgn Picture2.hwnd, hRgn, True
SelectClipRgn Picture2.hdc, hRgn


Picture2.Picture = Picture1.Image


Picture3.AutoRedraw = True
SavePicture Picture3.Image, "d:/1234.bmp"
End Sub


Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.PSet (X, Y)
ReDim Preserve ap(n)

ap(n).X = X
ap(n).Y = Y
If n > 0 Then Picture1.Line (ap(n - 1).X, ap(n - 1).Y)-(ap(n).X, ap(n).Y)
ap(n).Y = Y
n = n + 1
End Sub

Private Sub Form_Load()


Picture1.ForeColor = vbBlue
Picture1.DrawWidth = 2


End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Picture2.Move X - offsetX, Y - offsetY
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

blnDragging = False
ReleaseCapture

End Sub

Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub


...全文
191 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-01-08
  • 打赏
  • 举报
回复
建议楼主有工夫还不如对照最新版MSDN研究如何用GDI+操作带Alpha通道的PNG图绘图技术。 DrawImage Methods -------------------------------------------------------------------------------- This topic lists the DrawImage methods of the Graphics class. For a complete list of methods for the Graphics class, see Graphics. Graphics::DrawImage(Image*,Point*,INT) Graphics::DrawImage(Image*,INT,INT) Graphics::DrawImage(Image*,Point&) Graphics::DrawImage(Image*,REAL,REAL) Graphics::DrawImage(Image*,PointF&) Graphics::DrawImage(Image*,PointF*,INT) Graphics::DrawImage(Image*,REAL,REAL,REAL,REAL,REAL,REAL,Unit) Graphics::DrawImage(Image*,RectF&) Graphics::DrawImage(Image*,INT,INT,INT,INT) Graphics::DrawImage(Image*,PointF*,INT,REAL,REAL,REAL,REAL,Unit,ImageAttributes*,DrawImageAbort,VOID*) Graphics::DrawImage(Image*,Rect&,INT,INT,INT,INT,Unit,ImageAttributes*,DrawImageAbort,VOID*) Graphics::DrawImage(Image*,Point*,INT,INT,INT,INT,INT,Unit,ImageAttributes*,DrawImageAbort,VOID*) Graphics::DrawImage(Image*,REAL,REAL,REAL,REAL) Graphics::DrawImage(Image*,Rect&) Graphics::DrawImage(Image*,INT,INT,INT,INT,INT,INT,Unit) Graphics::DrawImage(Image*,RectF&,REAL,REAL,REAL,REAL,Unit,ImageAttributes*,DrawImageAbort,VOID*) Graphics::DrawImage(Image*,RectF&,RectF&,Unit,ImageAttributes*) Graphics::DrawImage(Image*,RectF*,Matrix*,Effect*,ImageAttributes*,Unit*) Graphics::GetClip Method -------------------------------------------------------------------------------- The GetClip method gets the clipping region of this Graphics object. Syntax Status GetClip( Region *region ) const; Parameters region [out] Pointer to a Region object that receives the clipping region. Return Value If the method succeeds, it returns Ok, which is an element of the Status enumeration. If the method fails, it returns one of the other elements of the Status enumeration. Example The following example sets a clipping region. Next, the code gets the clipping region, stores it in a Region object, and then uses the stored object to fill the region. Show Example VOID Example_GetClip(HDC hdc) { Graphics myGraphics(hdc); // Set a clipping region. myGraphics.SetClip(Rect(0, 0, 200, 100)); // Get the clipping region. Region clipRegion; myGraphics.GetClip(&clipRegion); // Fill the clipping region of the myGraphics object. myGraphics.FillRegion(&SolidBrush(Color(255, 0, 0, 0)), &clipRegion); } Method Information Stock Implementation gdiplus.dll Header Declared in Gdiplusgraphics.h, include gdiplus.h Import library gdiplus.lib Minimum availability GDI+ 1.0 Minimum operating systems Windows 98/Me, Windows XP, Windows 2000, Windows NT 4.0 SP6 See Also Graphics::GetClipBounds Methods, Graphics::ResetClip, Graphics::SetClip Methods, Region, Clipping with a Region, Clipping
cxy5636917 2015-01-08
  • 打赏
  • 举报
回复
请教大家继续。 呼叫高手。
cxy5636917 2015-01-08
  • 打赏
  • 举报
回复
网友“能量系”说是用这个bitblt 光栅常数用这两个 PATPAINT SRCAND 我对光栅搞得头都大了,还是没弄明白、
cxy5636917 2015-01-08
  • 打赏
  • 举报
回复
网友给了个提示【逻辑或 逻辑与】,是bitblt吗?我对个api的光栅常数实在搞不明白。 继续请教大家了。
cxy5636917 2015-01-08
  • 打赏
  • 举报
回复
谢谢 zhao4zhong1 gdi+的东西一点也不会。 “能量系”透露了一点。什么mask图。 大家从这个方向看看。我正搜寻这方面资料。
cxy5636917 2015-01-07
  • 打赏
  • 举报
回复
bcrun 2015-01-07
  • 打赏
  • 举报
回复
是自定义多边形区域进行复制吧,有用。

1,486

社区成员

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

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