Results 1 to 7 of 7

Thread: [RESOLVED] Cairo Surface Image Splitting [L-Plate Learner Edition]

  1. #1

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Resolved [RESOLVED] Cairo Surface Image Splitting [L-Plate Learner Edition]

    Name:  Clipping A Surface Image.jpg
Views: 311
Size:  62.1 KB
    Hi All,
    Just wondering what I'm doing wrong. Do I need to Clip, TranslateDrawings or some combination or other?
    I have a surface with a picture (with some transparent bits), I would like to copy said image to two other surfaces, but there's a problem and my understanding is very lacking.
    So far, I think I'm supposed to 'Clip define' the 'My_Surface', then copy that to Surface_A? Somehow? I don't quite get it. Is that what I'm supposed to do?

    I've tried RenderingSurfaceContent (OK), then TranslateDrawings on the new surfaces, but it appears the entire image is copied despite the small surface area. I even went so far as to 'clip' that, but it's not as expected. The Pycario documentation isn't much help.

    Anyone with knowledge?

    And for the interested, it's for the 'lip' manipulation section of Avatar-Facemaker thingy.
    Have a few low variance maidens for your trouble, built on the above thing I'm learning/testing. Still needs lots of hair styles, noses, lips etc. Currently building them. Hopefully someone can help me with the latest issue, so I can move forward. Many Thanks.

    Name:  Low Variance Faces Small Version.jpg
Views: 299
Size:  16.0 KB

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Cairo Surface Image Splitting [L-Plate Learner Edition]

    Below is an example, which demonstrates how to use the new .CropSurface-Method -
    (which is part of RC6 since two versions or so...)

    The code first downloads the attached image of your previous post - which was made up from four 150x150 parts.
    It then Splits these 4 parts out of the downloaded Parent-Surface -
    and renders them vertically onto the Parent-Form-Context (all in the little SplitIt-routine).

    Code:
    Option Explicit
    
    Private CC As cCairoContext
    
    Private Sub Form_Load()
      Set CC = Cairo.CreateSurface(1024, 768).CreateContext 'the Form-covering Main-Context (and -Surface)
          CC.Paint 1, Cairo.CreateCheckerPattern 'ensrue a BackGround
      
      SplitIt Cairo.CreateSurface(0, 0, , wget("https://www.vbforums.com/attachment.php?attachmentid=183265"))
     
      Set Me.Picture = CC.Surface.Picture
    End Sub
    
    Sub SplitIt(SrfToSplit As cCairoSurface)
      Dim i As Long, Parts(0 To 3) As cCairoSurface
      For i = 0 To 3
        Set Parts(i) = SrfToSplit.CropSurface(i * 150, 0, 150, 150)
        CC.RenderSurfaceContent Parts(i), 0, i * 150
      Next
    End Sub
    
    Public Function wget(URL As String) As Byte() 'just a little download-helper
           Dim http As Object
           Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
               http.Open "GET", URL, 0: http.Send
        wget = http.ResponseBody
    End Function
    Ediit:
    In case you're wondering what the CropSurface-method does under the covers -
    it is really quite simple (Me being the Surface-Object the method is called on):
    Code:
    Public Function CropSurface(x, y, dx, dy) As cCairoSurface
      Set CropSurface = Cairo.CreateSurface(dx, dy)
          CropSurface.CreateContext.RenderSurfaceContent Me, -x, -y
    End Function
    HTH

    Olaf
    Last edited by Schmidt; Dec 11th, 2021 at 08:14 PM.

  3. #3

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Surface Image Splitting [L-Plate Learner Edition]

    Thank you Olaf, it's borking on this sub and function for me:
    ------------------------------------------
    Sub SplitIt(SrfToSplit As cCairoSurface)
    Dim i As Long, Parts(0 To 3) As cCairoSurface
    For i = 0 To 3
    Set Parts(i) = SrfToSplit.CropSurface(i * 150, 0, 150, 150)
    ....
    ------------------------------------------
    "Method Or Data Member Not Found."

    Have I missed something fundamental? I added in latest RC6 reference.

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Cairo Surface Image Splitting [L-Plate Learner Edition]

    Quote Originally Posted by -Corso-> View Post
    Set Parts(i) = SrfToSplit.CropSurface(i * 150, 0, 150, 150)
    ....
    ------------------------------------------
    "Method Or Data Member Not Found."

    Have I missed something fundamental? I added in latest RC6 reference.
    I've included it since version 6.0.9, I think...
    You can check your current version e.g in the immediate-window via:
    ?New_c.Version

    If you don't want to download and re-register 6.0.9, then just use the non-integrated helper from here:
    https://www.vbforums.com/showthread....=1#post5537014

    Olaf

  5. #5

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Surface Image Splitting [L-Plate Learner Edition]

    Ah! I did have the old version. Wah, you update so fast. That got your code working. Thanks Olaf!
    I'll take a close look now and see how it runs. Many thanks again!

    Name:  images.jpg
Views: 240
Size:  55.6 KB

  6. #6

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Surface Image Splitting [L-Plate Learner Edition]

    Ignore this post. It's magically working again. Panic over. Mods, can you delete it?
    ---------------------------------------------------
    Ah! I wrecked something. Now the Avatar program fails to run since the RC6 Upgrade. I can't get any of these AddImage statements working anymore. ie:

    Cairo_Tool_Set.ImageList.AddImage "Minimum Face", App.Path & "\Face Maker Resources\Minimum Face\Minimum Face Basic.png"

    I get the error: "Object Variable or With Block Variable Not Set"

    From my declarations module: I use Cairo_Tool_Set as the image list handler.
    Global Cairo_Tool_Set As cCairo 'Manager (2D Drawing Manager Functions)' <- Normally all good.

    Do I have to write it out another way now?
    ---------------------------------------------------
    Last edited by -Corso->; Dec 11th, 2021 at 11:43 PM.

  7. #7

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Surface Image Splitting [L-Plate Learner Edition]

    Annnd, just like that we have duck mouth and pouty sliders.
    Thank you OLAF!!!!!!!!!!!!
    Name:  Simple Lip Adjust.jpg
Views: 234
Size:  39.8 KB

    PS: Watching elf ears wiggle in real time is bizarrely cute.

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