I’m working on making a copy of an ImageSet picture for use in a HiDPI app, and subsequently writing code to modify the various bitmaps in the ImageSet. I’m pretty sketchy on the new Picture type. The following is my first attempt to make a copy; it could clearly use some work.
Any suggestions?
dim picCopy as Picture // Copy of picture with ImageSet to build and return
dim bitMaps() as Picture
dim imageCt as Integer
dim pImagePic, pImagePicMutiableBitmapClone as Picture
dim pImageCopyWithAlpha, pImageMask as Picture
dim imageIndex as Integer
imageCt = aPic.ImageCount
for imageIndex = 0 to ImageCt - 1
pImagePic = aPic.IndexedImage( imageIndex )
pImageMask = pImagePic.CopyMask
pImageCopyWithAlpha = New Picture( aPic.Width, aPic.Height )
pImageCopyWithAlpha.Graphics.DrawPicture( pImageCopyWithAlpha, 0, 0 )
pImageCopyWithAlpha.ApplyMask pImageMask // This fails with UnsupportedOperationException
#IF False then // Is this needed?
pImageCopyWithAlpha.Graphics.ScaleX = pImagePic.Graphics.ScaleX
pImageCopyWithAlpha.Graphics.ScaleY = pImagePic.Graphics.ScaleY
#ENDIF
bitMaps.Append pImageCopyWithAlpha
next
picCopy = New Picture( aPic.Width, aPic.Height, bitMaps )
return picCopy
[quote] #IF False then // Is this needed?
pImageCopyWithAlpha.Graphics.ScaleX = pImagePic.Graphics.ScaleX
pImageCopyWithAlpha.Graphics.ScaleY = pImagePic.Graphics.ScaleY #ENDIF[/quote]
This part is needed, but youll need to check if plimagepic.Graphics is Nil first.
You should also be transferring Horizontal and Vertical Resolutions between the pictures.
I have code that “appears” to be working now. It does include transferring the horizontal vertical resolutions; but not the scale factors.
I’m in the interesting position that I have code that works; but that I don’t fully understand. I’ve read the several Xojo articles on HiDPI several times. Are you aware of any simple examples out there that would help in my better understanding and learning of HiDPI?
I have code that “appears” to be working now. It does include transferring the horizontal vertical resolutions; but not the scale factors.
I’m in the interesting position that I have code that works; but that I don’t fully understand. I’ve read the several Xojo articles on HiDPI several times. Are you aware of any simple examples out there that would help in my better understanding and learning of HiDPI?
Thanks![/quote]
Sure! I did a blog post shortly after we updated the Xojo IDE.
I have a very high-priority need to disassemble an Image Set picture into its component bitmaps, re-colorize or perform other pixel-level changes on those bitmaps, and then reassemble them in to a new Image Set picture.
I have a very low-priority interest in some day dynamically creating Image Set pictures from their file-based “.png” components and say, referencing them from a dictionary by name rather than the IDE-composed Image Set pictures created at build-time.
Ok, so I’ve created an example project which shows a way to be able to manipulate each image in an image set using a delegate ( so you get a callback for each image in the set ) which then draws the final image set to a canvas.
Hey Greg, Kind of you to take the time to code this, very educational.
After a lot of head scratching and test coding, I think I finally have a finger on the problem. It seems my difficulty is in the difference in how images are read in from a Picture.Open vs obtained through a Picture.IndexedImage. In the former case I get a bitmap picture with a mask; in the latter case I get a new-style picture with alpha channel. In the case of the Mac, the latter presumably has a pre-multiplied alpha and so no mask can be derived. The code I’ve been updating for HiDPI reshades the mask, not the color bits. Thus the predicament. Knowing this distinction, I should be able to code around it.