Copying an ImageSet Picture

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

I wouldnt use drawpicture but …

this post might help
https://forum.xojo.com/conversation/post/442715

but thomas also avoided drawpicture eventually

[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 you’ll need to check if plimagepic.Graphics is Nil first.

You should also be transferring Horizontal and Vertical Resolutions between the pictures.

pImageCopyWithAlpha.ApplyMask pImageMask  // This fails with UnsupportedOperationException

This can happen if there is no mask and plimagemask is Nil.

Appreciated Greg,

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=443360:@Ed Kleban]Appreciated Greg,

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.

https://blog.xojo.com/2016/04/05/xojo-retinahidpi-the-journey-of-a-thousand-pixels/

And joe did one shortly thereafter

https://blog.xojo.com/2016/04/07/advanced-retinahidpi-bitmapforcaching-and-scalefactorchanged/

Yes, I’ve read both of those. They’ve been very helpful.

In terms of “simple examples” the thought was that users would primarily use Image objects in the IDE.

Is there something in particular that you’re stuck on?

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.

https://www.dropbox.com/s/fcgjg0021uxpev8/BlendImages.zip?dl=1

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.