• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Set Alpha for an NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set Alpha for an NSImage


  • Subject: Re: Set Alpha for an NSImage
  • From: Vance <email@hidden>
  • Date: Wed, 30 Jan 2008 10:27:07 -0800

Yes that is a very good point that I should have mentioned. The images I use are already pre-processes. So I don't have to worry about that. All non-pure black is considered to be cloud information.

Here is a sample image: http://aviationweather.gov/data/obs/sat/intl/ir_ICAO-A_bw.jpg (Lets ignore the countries outline)

Thanks!
-Vance

Filipe Varela wrote:
Yes but that raises a question which is whether you'll be replacing meaningful information based only on color. Your image may contain sections the same color as clouds which are not meant to be replaced.

You may want to dig into pattern recognition, which is way off-topic.

Cheers,

Filipe

On 2008/01/30, at 17:27, Vance wrote:

I want to replace the pure black as well as the black underneath the areas of shaded white.

The image I have contains satellite image of clouds. So replacing only the pure black will not make it look right when placed on background other then black.

Does that mean I have to process even non-pure black regions myself as well?

Thanks!
Vance

Filipe Varela wrote:
If you only want to replace pure black, iterate thru every pixel in the bitmap looking for black (rgb channels same value = 0). Whenever you find such a pixel, change it's alpha value to whatever you need.

ie
unsigned char buffer = [rep bitmapData];
unsigned char pixel; //temp
for (h=0; h<height; h++) {
for (w=0;w<width;w++) {
pixel = buffer + (h * numBytesPerPixel * width) + w * numBytesPerPixel;
//channel index depends on image format, check the attributes
//attribs: (alpha first, alpha premultiplied, etc)
//assume (example) that img is rgba. (0=red 1=green 2=blue 3=alpha)
if(pixel[0]==0 && pixel[1]==0 && pixel[2]==0) // all black. set alpha to max
pixel[3] = 255;
}
}


Your image is now transparent or fully opaque.

Cheers,

Filipe

On 2008/01/30, at 17:07, Vance wrote:

Hi,

I have an NSImage (black and white) that I want to replace the black color with transparency.

I want it to be replaced in such a way, so even the shades of gray look correct when overlayed on top of another color, lets say blue.

What is the best way of do this?

Thanks.
Vance
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Named image for regular folder? (From: Jim Correia <email@hidden>)
 >Re: Named image for regular folder? (From: Ken Thomases <email@hidden>)
 >Re: Named image for regular folder? (From: Matt Gough <email@hidden>)
 >Set Alpha for an NSImage (From: Vance <email@hidden>)
 >Re: Set Alpha for an NSImage (From: Filipe Varela <email@hidden>)

  • Prev by Date: Re: Named image for regular folder?
  • Next by Date: Re: insertText: without a NSWindow/NSView (or: Unicode input without NSView/Window)
  • Previous by thread: Re: Set Alpha for an NSImage
  • Next by thread: Re: Set Alpha for an NSImage
  • Index(es):
    • Date
    • Thread