|
-
Feb 10th, 2024, 04:21 PM
#1
Thread Starter
Fanatic Member
Help Needed: Resizing Images with Cairo in VB6
I'm using the Cairo graphics library in VB6 to work with PDFs by converting them to images for easier manipulation. My goal is to resize these images to a specific maximum width and height without losing the ability to view all details. However, I'm struggling with the resizing function using Cairo in VB6. Here's my attempt:
Code:
Public Function Resize(ByRef srf As cCairoSurface, ByVal uMaxWidth As Long, ByVal uMaxHeight As Long) As cCairoSurface
Dim lNewWidth As Long
Dim lNewHeight As Long
' Save original image for comparison
srf.WriteContentToPngFile "d:\path\before_resize.png" (looks as expected)
' Calculate new dimensions
ScaleImage srf.Width, srf.Height, uMaxWidth, uMaxHeight, lNewWidth, lNewHeight, scaleDownAsNeeded
' Create new resized image
Dim nNew As cCairoSurface
Set nNew = srf.CreateSimilar(CAIRO_CONTENT_COLOR_ALPHA, lNewWidth, lNewHeight, False)
Dim Ctx As cCairoContext
Set Ctx = nNew.CreateContext()
' Fill background (testing purposes)
Ctx.SetSourceRGBA 1, 0.5, 1, 0.5 (creates a pink surface as expected)
Ctx.Rectangle 0, 0, lNewWidth, lNewHeight
Ctx.Fill
' Attempt to render resized content
srf.CreateContext.RenderSurfaceContent nNew, 0, 0, 200, 200, CAIRO_FILTER_BEST, 0.5 (does not have any effect)
' Save resized image for comparison
nNew.WriteContentToPngFile "d:\path\after_resize.png" 'shows a pink image only.
' Need assistance correcting my approach.
End Function
I'm not sure how to properly use the Cairo library for resizing images. Assistance in correcting my approach would be appreciated.
Last edited by tmighty2; Feb 10th, 2024 at 04:28 PM.
-
Feb 10th, 2024, 05:07 PM
#2
Re: Help Needed: Resizing Images with Cairo in VB6
It looks like you have your surfaces backwards - you want to create the context for nNew and write the surface content of srf to it:
Code:
nNew.CreateContext.RenderSurfaceContent srf, 0, 0, 200, 200, CAIRO_FILTER_BEST, 0.5 (does not have any effect)
(I haven't tried it, so there might be other issues, but that one jumped out).
Last edited by jpbro; Feb 11th, 2024 at 01:37 PM.
-
Feb 11th, 2024, 06:18 AM
#3
Thread Starter
Fanatic Member
Re: Help Needed: Resizing Images with Cairo in VB6
Thank you very much! That was my mistake. It works now.
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
|