VB6
Windows 10
How could I crop a circle out of a picture, basically making a hole in the picture?
Printable View
VB6
Windows 10
How could I crop a circle out of a picture, basically making a hole in the picture?
If you want to redraw the picture with the hole you can create a round clip region, select the region into the hDC you are drawing on, then redraw the picture, and remove the clip region and delete it. Optionally, create round clip region XOR'd with the size of the image and fill the region with a solid color.
Option 1 APIs: SelectClipRgn, CreateRoundRecRgn or CreateEllipticRgn, DeleteObject
Option 2 APIs: Same APIs as above + CombineRgn, CreateRectRgn, CreateSlolidBrush, FillRgn
If this sounds 'greek' to you, maybe more details would help.
Attachment 149153
Here's a FORM with a 'hole'...albeit rectangular. Probably not what you're looking for. What do you want to see 'in the hole' of your picture? Some control behind it?
It is hard to know what you mean by "crop a circle" because you could paint it white, black, etc. but if you want transparency then there is more to the story. If you want something to "show through the hole" then you have to play games compositing images, or in some cases you could use layered windows.
Here's a simple demo that uses the layered child windows facility we've had since Windows 8 (but not before):
Er, on downlevel versions of Windows you'll only see "white" circles get painted. Normally a run in the IDE will do the same thing because to get layered child windows your process must be marked Win8-aware using an application manifest.
For those who want to check it out with a reference to vbRichClient5 (offering antialiasing on the Clip-Regions,
and working on any Win-OS), here's replacement code for Form1 of dilettantes WIA-demo.
Producing this:Code:Option Explicit
Private CC As cCairoContext
Private Sub Form_Load()
Cairo.ImageList.AddImage "BackDrop", LoadResData("BACKDROP", "PNG")
Cairo.ImageList.AddImage "Curtain", LoadResData("CURTAIN", "PNG")
ScaleMode = vbPixels
Set CC = Cairo.CreateSurface(ScaleWidth, ScaleHeight).CreateContext
Redraw
Picture1.Visible = False '<- we don't need that
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Redraw X, Y, 100
End Sub
Private Sub Redraw(Optional ByVal xc&, Optional ByVal yc&, Optional ByVal Radius&)
CC.RenderSurfaceContent "Curtain", 0, 0
CC.ARC xc, yc, Radius
CC.Clip
CC.RenderSurfaceContent "BackDrop", 0, 0
CC.ResetClip
Set Picture = CC.Surface.Picture
End Sub
Private Sub Form_Terminate()
New_c.CleanupRichClientDll
End Sub
http://vbRichClient.com/Downloads/An...edClipping.png
Olaf