Remove alpha channel from .psd

I’m loading photoshop PSDs that have an alpha channel. I can’t figure out how to delete the alpha channel, or load the PSDs without the alpha channel.

if I try

Var np As New Picture(p.Width, p.Height, 24)
np = Picture.Open(f)

It ignores the set btt deptt and opens it as a 32-bit image with alpha channel.

Is there some way to open the PSD without the alpha channel, or copy the image without the alpha channel?

Just create a new Picture object without the alpha channel and draw the PSD picture into it.

Use instead:
Picture(p.Width, p.Height)

That is what Eric meant.

I still get the alpha channel coming though.
No matter what you set the bit depth to when using new Picture(pic.Width, pic.Height, 24) Xojo ALWAYS sets it to 32-bit. :roll_eyes:

Var pic As picture
pic = Picture.Open(obj.FolderItem)

If pic <> Nil Then
  
  var n as new Picture(pic.Width, pic.Height)
  n.Graphics.DrawPicture(pic, 0, 0)
  ImageViewer1.Image = n
  
End If

I would create a picture object, draw white (or whatever color) to its graphics context, then load the PSD and draw it to that same context.

I’ve tried that. I still get the alpha channel showing up in the image, this time as white instead of black.

Here’s my test app, with a sample psd. I drag it onto the window and not the ImageViewer
Remove_Alpha_Channel.zip (11.9 KB)

If you do not specify a bit depth then the picture will have an alpha channel. If you specify a depth of 24 it will not.

var n as new Picture(pic.Width, pic.Height, 24)
n.Graphics.DrawPicture(pic, 0, 0)

should do the trick.

I think I understand what you’re trying to do now. You want to use a PSD as a mask for a Xojo picture object? If so, you can draw that to the Picture.Mask graphics context if creating a picture with a defined depth, or use ApplyMask otherwise.

It doesn’t matter what bit depth you specify, the picture is ALWAYS 32 bit!

I’ve tried setting it to 1, 2, 4, 8, 16 and 24. The picture is ALWAYS 32 bit depth

What I want is the gradient image without the alpha channel.

The psd files I have all have an alpha channel, so I want the RGB image without an alpha channel or mask.

Then you can either do this or modify the original PSD.

I would create a picture object, draw white (or whatever color) to its graphics context, then load the PSD and draw it to that same context

Oh, I see what you’re looking for. Use Picture.CopyColorChannels to get a version of the picture with the mask removed.

1 Like

Oh, that’s a good one. When did that slip in? 2016r3. Don’t know how I missed it.

It has been many many years since Xojo supported any other bit depth.

I used to have a use for 8 and 2 bit, long since had to find different ways to handle the requirement

It’s not the first time I see additions I’ve missed. I guess not everything is always mentioned.

…or the addition do not “speak” to the reader…

I saw that addition, but I do not saw the use I can do to it, then I do not “explorate it”, then I “forgot” it. (it was hiden below other things).

I suppose.

Yeah, but it is still true that specifying a depth (any depth; 24 is just a reminder of the fact that you are dealing with three RGB channels with 8 bits each) gives you a picture without an alpha channel whereas omitting the depth parameter creates a picture with an alpha channel. That’s according to the documentation and it’s actually true as revealed by checking Picture.HasAlphaChannel.