Canvas Paint Event ForeColor not completing

I have a canvas, into which I DrawPicture an image after drawing the background color of the canvas:

	Sub Paint(g As Graphics, areas() As REALbasic.Rect)
	  #if TargetLinux
	    g.forecolor = &c36353500
	  #ElseIf TargetMacOS
	    g.forecolor = &c36333600
	  #endif
	  g.FillRectangle(0, 0, g.Width, g.Height)
	  g.DrawPicture(owclogo_56, 0, 0)
	End Sub

Under Linux, the color is correct and the background of the canvas is the same color as the window I’m drawing onto (I’m covering a default graphics that is baked into the window’s background). However, on macOS, the background is black (0,0,0).

Screen Shot 2021-01-05 at 11.40.18 AM

Also, when type “g.Fo[TAB]” in that event, ForeColor does not autocomplete, nor is it listed as an option in the popup list.

Is painting using a FillRectangle broken on macOS?

ForeColor became DrawingColor in API 2.0

If you remove the drawpicture do you still see black or is the picture drawing causing the black background?

Of course it did :triumph:

No - but the fill color that IS drawn is incorrect (I used the dropper to get the color of the window’s backdrop image).

The image is a PNG with a transparent background. Why would that work on Linux and fail on macOS? Canvas bug?

1 Like

That’s above my pay grade :wink: Probably some mac magic where they change colors depending on the moon phase or how bright the room is or some other daft metric. Someone else might be able to shed some light on that one (pun intended).

Possibly an issue with the way the transparency is set on the image, or the way the framework loads it in, or the moon phase :wink: Try the ball image from here Scrollbar nightmare - #4 by anon20074439

That one’s clean. Could it be that the image I’m using is a multiple image, hi-def support PNG (even though I’ve never seen this before)? The images that make up the xojo_image were created with Preview.

Highly likely, it could be that its got multiple images in there or that it was made with preview or a mix of both or that xojo’s png image loader fails on one of those combos, but without testing its a bit of a guess.

What’s strangest is that the image and color are correct on Windows and Linux.

Maybe windows and linux just selects the first image it comes across where as the mac version tries to intelligently select the correct image which either has an issue with the transparency or it forgets to load the transparency. Again not sure, sorry I can’t really help any more, maybe some of the more mac centric peeps can help out here.

1 Like

We would need the image source (or complete example project) to dig any deeper.

It may be due to the ratios of the three images in. the xojo_image being off by 1 pixel and the @2 image being slightly scaled. I’m going back to the original AI image and recut it so that it’s properly divisible nd reimport them.

No, I have one or two pictures where the dimensions are a pixel or 2 off and I’ve had any problems with the transparent areas.

The color you get on a Mac will vary according to color profiles.
While I know ‘pros’ want this stuff, it’s a pain.

In your shoes, I would try this for a ‘quick fix’:
(ps I personally dont like IF… ELSEIF on the grounds of clarity)

Code…

Sub Paint(g As Graphics, areas() As REALbasic.Rect)
       g.forecolor = &c36333600  //default value 
	  #if TargetLinux
        //use something else on Linux
	    g.forecolor = &c36353500
	  #endif
	  g.FillRectangle(0, 0, g.Width, g.Height)
	  g.DrawPicture(owclogo_56, 0, 0)
	End Sub

The OWC image is a simple 2 color thing… invert it and apply the inversion as a mask.
That will guarantee you have control of what is shown and what is not.

1 Like

Do you have a test project you can share?

That sorted it. setting the forecolor and then using #if Not TargetMacOS got rid of the black background.

Now to just find the REAL matching color …