Is ShadowColor ignored when attempting a shadow around an image?

This code for ShadowBrush.ShadowColor works well when drawing a graphic in a canvas, but when attempting with an image, it seems as though the shadow color is ignored and only displays as black. Is this expected? Is there a way around this without having to get creative and drawing a graphic underneath the actual image?

'shadow
g.ShadowBrush = new ShadowBrush
g.ShadowBrush.BlurAmount = 10
g.ShadowBrush.ShadowColor = color.LightGray
g.ShadowBrush.Offset.X = 5
g.ShadowBrush.Offset.y = 5

g.DrawPicture(PANEL_ReviewGuide, 0, 0, g.Width - 10, g.Height - 10,0,0,PANEL_ReviewGuide.Width, PANEL_ReviewGuide.Height)

Same code but with a red round rectangle instead of the image. Notice the light gray shadow

looks like some weird bug to me, suggest you report it. What OS is this on?

Was wondering this too Sam, thanks. This was on Mac 10.14, running Xojo 2021 r1. Will try also on Windows tomorrow and will file a report then too with a sample project

1 Like

is your image saved as png with alpha?
was the first image a round rectangle with icon on it? (means one image)

[quote=“Ryan_Hartz, post:1, topic:64845”]

g.ShadowBrush = new ShadowBrush
g.ShadowBrush.BlurAmount = 10
g.ShadowBrush.ShadowColor = color.LightGray
g.ShadowBrush.Offset.X = 5
g.ShadowBrush.Offset.y = 5

when you write everything on one line
it should work
with me anyway

g.ShadowBrush = New ShadowBrush(5,5,Color.LightGray,10)

1 Like

Confirmed. Mac Mojave, Xojo 2021 R2

Btw the ShadowBrush properties do not auto-complete which makes me suspect that you can’t set them.

What does a bold property in the docs mean again? Read only? So maybe these properties can only be set in the Constructor?

Yup, I think that’s it. A really stup… not very user-friendly way of relaying information. How about having that on every page behind the PROPERTIES header:

“Properties in bold are read-only and can only be set in a Constructor”

g.width = 100 will result in a “Cannot assign a value to this property”.

but

g.ShadowBrush.Offset.X = 5 does NOT raise an error (but should)

1 Like

if this the case yeah should be a compiler error if things can not be assigned or useless.
try (or this one line mentioned)

'shadow
var br As new ShadowBrush
br.BlurAmount = 10
br.ShadowColor = color.LightGray
br.Offset.X = 5
br.Offset.y = 5
g.ShadowBrush = br

The one-liner did the trick. Seems as though the multiline should work as it does for a drawn image. I just submitted a feedback report case
<https://xojo.com/issue/65480>

Here is what the project looks like

Thanks for the help all!

2 Likes

Did you even read what I wrote???

Btw whether they SHOULD be changeable is a different question. I would actually argue yes, but I don’t know the implementation problems …

On the macOS it is probably using the CoreGraphics function CGContextSetShadowWithColor (Apple Developer Documentation). Which at the OS framework level is simply a function not a class.

NSShadow is a class and not a function, but I’ve never tried to use that on a graphics context (so I don’t know if this can be used in that way or not).

But like you say, it really depends on how Xojo are translating their shadowBrush class to system API.

I did but thought you were highlighting the inconsistencies in the docs. It does make it seem as though you can change these as in the multi line code. I found that either in the examples project or on the forum and implemented it in my project. Either way, we should suspect it should work modifying using the multi line code in both the drawn red square and the picture and with the single line, or, if they cannot/should not be able to be changed calling g.ShadowBrush… and only when using the constructor, then it should not work when drawing the red square.

Just was pointing out an inconsistency that may need to be improved upon, either way

I’m always learning. This stuff may come as second nature to many of you, but for those of us (me) who take it as it is and run with it, I’d expect when A = B that B should also = A :slight_smile: