Being a longtime REAL/Xojo user, I’m really confused about images and masks and transparency - now with Hi-DPI which I need to support.
I keep losing my transparency. Let’s be simple.
I have a PNG called ‘player_play’ with a transparent background. It’s 200px and it’s in my Hi-DPI app as a Image. I want to display it in a 32x32 Canvas object. I do this in the Open event, and I lose my transparency.
I used to be able to deal with this much better, but with Hi-DPI I don’t have the transparency options, and ‘player_play’ doesn’t seem to show any Mask when I look at it in the debugger under Contents.
Dim P As Picture
P = Copy32(player_play)
Me.Backdrop = P
Function Copy32(SrcPic As Picture) As Picture
Dim P as Picture
Dim g As Graphics
P = New Picture(32, 32, 32)
g = P.Graphics
g.DrawPicture(SrcPic, 0, 0, 32, 32, 0, 0, SrcPic.Width, SrcPic.Height)
I know I’m 10 years behind here, how do I keep my transparency in Hi-DPI?
Ok, first of all make sure you are using “images” in the IDE so you get the benefits of the HiDPI system. It’ll automatically get you the right resolution for what you’re trying to do. Keep in mind that Images can’t be written to.
Second, stop using the Picture constructor that takes takes bits. If at all possible use Window.BitmapForCaching. It will get you a picture that is configured for the screen that the window is on.
// — You need a 2x image for HIDPI. p = new picture( 64, 64 )
Then at the end of the routine, add the following line. It’s not “technically” correct as your image only contains a 2x image and not a 1x image, but it is enough to fool the system. return new picture( 32, 32, array( p ) )
keving: Well, you’re right, but the problem is that, with Hi-DPI selected, I can’t do all the copying of Mask and transparency things I used to be able to do. So Copy32 is doing what I think it is, and I know it’s not enough, which was the essence of my question. As Greg implied, the manual does say about BitmapForCaching: “This image [created by BitmapForCaching] supports Alpha Channels (not masked images)”.
For static resources, create a picture containing a set of pictures the represent the different resolutions and let the OS choose the appropriate version. Depending on what your content is you might be able to scale a single source picture for both resolutions or you might want two different representations. Here is an example using my scale function:
Dim p(1) As Picture
p(0) = ScalePictureWithAlpha(sourcePicture, 32, 32)
p(1) = ScalePictureWithAlpha(sourcePicture, 64, 64)
mImageSet_ = New Picture(32, 32, p)
(where mImageSet_ is a Picture property that you could then draw within the Paint event)
NOTE. I haven’t used Hi-DPI much so take all of this with a pinch of salt. I’m sure others can probably give you much better advice.
Public Function ScalePictureWithAlpha(pSourcePicture As Picture, pWidth As Int32, pHeight As Int32) as Picture
Dim theResult As Picture
Dim tempMask As Picture