Results 1 to 9 of 9

Thread: Crop A Circle From A Picture

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    127

    Question Crop A Circle From A Picture

    VB6
    Windows 10

    How could I crop a circle out of a picture, basically making a hole in the picture?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Crop A Circle From A 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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Crop A Circle From A Picture

    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?

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Crop A Circle From A Picture

    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):

    Name:  sshot.png
Views: 1310
Size:  12.4 KB
    Attached Files Attached Files
    Last edited by dilettante; Jul 5th, 2017 at 01:31 PM.

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Crop A Circle From A Picture

    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.

  6. #6
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Crop A Circle From A Picture

    Quote Originally Posted by dilettante View Post
    Here's a simple demo ,,,
    WAY cool !!

  7. #7
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: Crop A Circle From A Picture

    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.

    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
    Producing this:


    Olaf

  8. #8
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: Crop A Circle From A Picture

    Quote Originally Posted by Schmidt View Post
    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.

    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
    Producing this:


    Olaf
    Is there a development document about vbRichClient.dll ?

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: Crop A Circle From A Picture

    Quote Originally Posted by xxdoc123 View Post
    Is there a development document about vbRichClient.dll ?
    The usage of the cairo-graphics-classes is explained in great detail in the cairo-tutorial on vbRichClient.com (Section Demos>GUI>CairoDrawing)
    The other larger part (SQLite) is explained in another large tutorial in section Demos>SQLite.

    Olaf
    Last edited by Schmidt; Jul 8th, 2017 at 07:48 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width