|
-
Nov 17th, 2024, 12:38 PM
#1
Thread Starter
Fanatic Member
-
Nov 18th, 2024, 10:04 AM
#2
Re: Cairo graphics (RC6): Dilate image with transparent regions
If you create a blurred version of your image, and then paint that with a single colour, you should be able to use that as an outline for your actual image.
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Nov 18th, 2024, 01:02 PM
#3
Thread Starter
Fanatic Member
Re: Cairo graphics (RC6): Dilate image with transparent regions
Thank you.
I feel so stupid, I don't manage it.
I tried it for 4 hours.
Can you fix my code?
Code:
Public Function CreateDilate(ByRef uSrc As cCairoSurface, ByVal uColor As Long, ByVal uDilateWidth As Long) As cCairoSurface
Dim sBlur As cCairoSurface
Set sBlur = uSrc.CreateSimilar(CAIRO_CONTENT_COLOR_ALPHA, , , True)
sBlur.FastBlur 30
With Cairo.CreateSurface(uSrc.Width * (uDilateWidth * 2), uSrc.Height * (uDilateWidth * 2)).CreateContext
.RenderSurfaceContent sBlur, 0, 0, sBlur.Width, sBlur.Height, , 1
.SetSourceColor uColor
.MaskSurface .Surface
Set CreateDilate = .Surface
End With
End Function
-
Nov 18th, 2024, 01:09 PM
#4
Re: Cairo graphics (RC6): Dilate image with transparent regions
Try this code (the meat was written by Olaf, I just did some surrounding stuff and added comments to try to explain what the code is doing):
Code:
Dim lo_SrfImage As RC6.cCairoSurface
Dim lo_SrfBorder As RC6.cCairoSurface
Dim b() As Byte
Dim re As Byte
Dim gr As Byte
Dim bl As Byte
' Load main image
Set lo_SrfImage = Cairo.CreateSurface(0, 0, , "C:\myimage.png") ' Change path to path to your image
' Create blurred image surface for the border
Set lo_SrfBorder = lo_SrfImage.GaussianBlur(15, 15) ' Change this number to change the border width
' Get border colour RGB
bl = (vbRed And &HFF0000) \ &H10000 ' Change vbRed to whatever colour you want the border to be
gr = (vbRed And &HFF00&) \ &H100&
re = vbRed And &HFF
' Remove transparency and change colour
lo_SrfBorder.BindToArray b
For y = 0 To UBound(b, 2): For x = 0 To UBound(b, 1) Step 4
If b(x + 3, y) > 5 And b(x + 3, y) < 255 Then 'when semi-transparent (in a certain range)...
' Colors are stored in BGRA order
b(x + 0, y) = bl
b(x + 1, y) = gr
b(x + 2, y) = re
b(x + 3, y) = 255 '...set all 4 components of the whole pixel to fully opaque
Else
b(x + 0, y) = 0 '...set all 4 components of the whole pixel to fully transparent
b(x + 1, y) = 0
b(x + 2, y) = 0
b(x + 3, y) = 0
End If
Next x
Next y
lo_SrfBorder.ReleaseArray b
' Draw original image over top border image
lo_SrfBorder.CreateContext.RenderSurfaceContent lo_SrfImage, lo_SrfBorder.Width / 2 - lo_SrfImage.Width / 2, lo_SrfBorder.Height / 2 - lo_SrfImage.Height / 2
lo_SrfBorder.DrawToDC Me.hDC ' Draw the image with border
Should produce a result like this:
-
Nov 18th, 2024, 02:06 PM
#5
Thread Starter
Fanatic Member
Re: Cairo graphics (RC6): Dilate image with transparent regions
-
Nov 18th, 2024, 02:50 PM
#6
Thread Starter
Fanatic Member
Re: Cairo graphics (RC6): Dilate image with transparent regions
I am trying to locate a post that is about dropshadow with RC6 / Cairo Graphics, but I don't find one.
Can somebody recommend his way of doing it?
-
Nov 18th, 2024, 03:19 PM
#7
Re: Cairo graphics (RC6): Dilate image with transparent regions
Might be better to start a new topic for this, but I recommend playing around with GaussianBlur, then convert to grayscale (using Olaf's method here), and maybe even play with the gamma/brightness/contrast using the CCairoSurface.AdjustColors method. Finally draw the shadow at an XY position offset from center and draw the main image over top at the center.
-
Nov 18th, 2024, 03:29 PM
#8
Thread Starter
Fanatic Member
Re: Cairo graphics (RC6): Dilate image with transparent regions
Thank you, I did that now.
-
Nov 18th, 2024, 09:08 PM
#9
Thread Starter
Fanatic Member
Re: Cairo graphics (RC6): Dilate image with transparent regions
You mean this one?
->
Code:
Private Sub RenderDisabledIco(CC As cCairoContext, Srf As cCairoSurface, x, y)
CC.SetSourceColor vbWhite
CC.MaskSurface Srf, x, y
CC.Operator = Cairo_OPERATOR_HSL_LUMINOSITY
CC.RenderSurfaceContent Srf, x, y
CC.Operator = CAIRO_OPERATOR_OVER
End Sub
They greyscale functions on that page produce the following image for me which is perhaps "disabled", but not really greyscale:
Last edited by tmighty2; Nov 18th, 2024 at 09:14 PM.
-
Nov 18th, 2024, 09:33 PM
#10
Thread Starter
Fanatic Member
Re: Cairo graphics (RC6): Dilate image with transparent regions
Ok, I got it now, I hope.
I didn't use the right parameter for Make(...), and Y in that function should be 0, not 1.
Here is the full code now:
Code:
Public Sub MakeSemiTransparentFullyOpaqueBlack(Srf As cCairoSurface, ByVal uShadowAlpha As Byte, Optional ByVal UpperAlpha As Byte = 128)
Dim X As Long, y As Long, b() As Byte
Srf.BindToArray b
For y = 0 To UBound(b, 2): For X = 0 To UBound(b, 1) Step 4
If b(X + 3, y) > 0 And b(X + 3, y) > UpperAlpha Then 'when semi-transparent (in a certain range)...
b(X + 0, y) = 0
b(X + 1, y) = 0
b(X + 2, y) = 0
b(X + 3, y) = uShadowAlpha '255 = completely black/opaque 0=completely transparent, 124=halftransparent
End If
Next X, y
Srf.ReleaseArray b
End Sub
Public Function CreateDropShadow(ByRef uSurf As cCairoSurface, ByVal uRadius As Long, ByVal uColor As Long, ByVal uAlpha As Double) As cCairoSurface
Dim btAlpha As Byte
btAlpha = pConvertAlpha(uAlpha)
Dim nCopyOrigS As cCairoSurface
Set nCopyOrigS = uSurf.CreateSimilar(CAIRO_CONTENT_COLOR_ALPHA, , , True)
MakeSemiTransparentFullyOpaqueBlack nCopyOrigS, btAlpha, 0
'debugging:
'nCopyOrigS.WriteContentToPngFile "d:\weg\bla2.png"
Dim nCopyOrigC As cCairoContext
Set nCopyOrigC = nCopyOrigS.CreateContext
Dim lRetRadius&
lRetRadius = uRadius
Set nCopyOrigS = nCopyOrigS.GaussianBlur(lRetRadius / 2, lRetRadius, False)
Dim lWidthOrig&
lWidthOrig = uSurf.Width
Dim lWidthShadow&
lWidthShadow = nCopyOrigS.Width
Dim lAdd&
lAdd = (lWidthShadow - lWidthOrig)
' Me.Caption = "Input radius: " & uRadius & ", ret radius: " & lRetRadius & ", diff: " & lAdd
Set CreateDropShadow = nCopyOrigS
End Function
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
|