0

I have some .bmp files that have some color (maybe black) that is supposed to show as transparent when the graphic is displayed on top a form, so the form color comes through the transparent areas. But by default, when I put these images in an Image View, the black/transparent areas show up as BLACK!

I'm thinking I need to either: - alter how the NSImageView shows the image, so that a certain color is transparent, or - modify the .bmp files somehow to make that color suitable for transparency in an NSImageView

But I don't know enough about graphics files, transparency(alpha), NSImageView, nor the image editing tools. I'm trying to use Gimp, but...not sure what I'm doing yet. It seems like there is already a color that should be transparent in the current .bmp file.

I'm sure its something simple for setting NSImageView, or editing my file, or perhaps making a mask for the image, but I don't know how yet. I've looked at various filters in IB for NSImageView, but have not found where to set the transparent color, nor how to grab that color from the image file to make sure I use the correct value.

Thanks in advance for any assistance. (I tried to post some images, but because I'm new, I could not.)

Beau

Bo A
  • 138
  • 9

1 Answers1

0

I'm not a Cocoa developer, but in Gimp try adding an alpha channel to your image (a layer mask, perhaps) then saving as a 32-bit PNG image (with an alpha channel), then load that PNG directly into your NSImageView. If you want to make the black pixels transparent in Gimp use the magic-wand tool to select them (use magic-wand with 0 tolerance) and just delete the contents of the selection then save as a PNG directly.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • I was looking for something like that, but looking at the image in Gimp, it appeared to have some kind of background, because it showed as a checkerboard. I think your answer might have been in the right direction if that hadn't been so. – Bo A Jun 17 '12 at 03:03
  • The checkerboard pattern means the area is transparent. If you change your zoom you'll see the checkerboard size remains the same even though the size on-screen of each pixel changes (this is why it's not a good idea to be at a zoom level where each checkerboard square is the same size as each pixel). – Dai Jun 17 '12 at 03:05
  • I used Gimp to open the .bmp file, and Save As a .png file. I then added that file to Xcode and used the .png instead of the .bmp on the NSImageView, and the transparency worked correctly (the form showed through the areas of the .png that were in the background color. This solves my problem. But I would like to know what the difference in the NSImageView handling of the .bmp and .png files is. – Bo A Jun 17 '12 at 03:06
  • My guess is that either the BMP was saved as a 24-bit bitmap (thus, lacking an alpha channel) or NSImageView doesn't support 32-bit bitmaps (I'm not a Cocoa developer, so someone please correct me if necessary). – Dai Jun 17 '12 at 03:08
  • Well, if Gimp added an alpha channel when I saved the file as a .png, it did it automatically, because I did not set anything but used the defaults when I Saved As .png. – Bo A Jun 17 '12 at 03:31
  • Examining my original .bmp, I now see that it does not have an alpha channel. So the old Windows software that used it must have either selected a color (I think Borland TImage uses the color of the lower left pixel), or it must have been set in the program. For an NSImageView on the mac, when I used Gimp to Save As a .png, it created an alpha channel, I see that in the info for the .png. How Gimp selected the correct color for the alpha channel, I have not figured out yet. – Bo A Jun 17 '12 at 13:27