-
Dec 11th, 2021, 06:33 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Cairo Surface Image Splitting [L-Plate Learner Edition]
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.
-
Dec 11th, 2021, 08:02 PM
#2
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.
-
Dec 11th, 2021, 08:39 PM
#3
Thread Starter
Hyperactive Member
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.
-
Dec 11th, 2021, 09:40 PM
#4
Re: Cairo Surface Image Splitting [L-Plate Learner Edition]
Originally Posted by -Corso->
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
-
Dec 11th, 2021, 10:15 PM
#5
Thread Starter
Hyperactive Member
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!
-
Dec 11th, 2021, 10:42 PM
#6
Thread Starter
Hyperactive Member
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.
-
Dec 11th, 2021, 11:59 PM
#7
Thread Starter
Hyperactive Member
Re: Cairo Surface Image Splitting [L-Plate Learner Edition]
Annnd, just like that we have duck mouth and pouty sliders.
Thank you OLAF!!!!!!!!!!!!
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|