can photoshop save a png with only alpha channel?

Member
Posts: 164
Joined: 2010.10
Post: #1
i have a black and alpha image.
i use texture2d from apple (a bit modified, i report some code)
Code:
// Create a variable which will store the CGImageRef from the image which has been passed in
        CGImageRef image;        
        
        // Grab the CGImage from the image which has been passed in
        image = [aImage CGImage];
        
        // Check to make sure we have been able to get the CGImage from the Image passed in.  If not then
        // raise an error.  We don't want the application to continue as a missing image could create unexpected
        // results
        NSAssert(image, @"ERROR - Texture2D: The supplied UIImage was null.");
        
        // Check to see if the image contains alpha information by reading the alpha info from the image
        // supplied.  Set hasAlpha accordingly
        CGImageAlphaInfo info = CGImageGetAlphaInfo(image);
        BOOL hasAlpha = ((info == kCGImageAlphaPremultipliedLast) ||
                    (info == kCGImageAlphaPremultipliedFirst) ||
                    (info == kCGImageAlphaLast) ||
                    (info == kCGImageAlphaFirst) ? YES : NO);
        
        // Check to see what pixel format the image is using
        if(CGImageGetColorSpace(image)) {
            if(hasAlpha)
                pixelFormat = kTexture2DPixelFormat_RGBA8888;
            else
                pixelFormat = kTexture2DPixelFormat_RGB565;
        } else  //NOTE: No colorspace means a mask image
            pixelFormat = kTexture2DPixelFormat_A8;




switch(pixelFormat) {        
            case kTexture2DPixelFormat_RGBA8888:
                colorSpace = CGColorSpaceCreateDeviceRGB();
                data = malloc(height * width * 4);
                context = CGBitmapContextCreate(data, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
                CGColorSpaceRelease(colorSpace);
                break;
                
            case kTexture2DPixelFormat_RGB565:
                colorSpace = CGColorSpaceCreateDeviceRGB();
                data = malloc(height * width * 4);
                context = CGBitmapContextCreate(data, width, height, 8, 4 * width, colorSpace, kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big);
                CGColorSpaceRelease(colorSpace);
                break;
                
            case kTexture2DPixelFormat_A8:
                data = malloc(height * width);
                context = CGBitmapContextCreate(data, width, height, 8, width, NULL, kCGImageAlphaOnly);
                break;                
            default:
                [NSException raise:NSInternalInconsistencyException format:@"Invalid pixel format"];
        }
i want that the image loaded is of format: kTexture2DPixelFormat_A8, but i don't know how to achive this.
thanks
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Save it as a greyscale image and load it as alpha. It's pretty much as simple as that.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #3
thanks for the quik reply! :-)
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #4
perhaps i'm doing something wrong because the image displayed is not the same as i saved, so, i think that the image i'm allocating and loading has not the correct format...
i have saved grayscale.png and loaded as alpha, tried with bitmap and other format...
i'm trying with this method:
CGImageGetColorSpace-> The source color space for the specified bitmap image, or NULL if the image is an image mask
i need to create an image mask, tried with black and white bitmap, but the function returns like the image is a RGB (without alpha)
what kind of image can i pass to have CGImageGetColorSpace returns NULL (image mask)?

thanks a lot for help
Quote this message in a reply
Moderator
Posts: 3,574
Joined: 2003.06
Post: #5
I would highly recommend using SOIL instead. It is soooo much simpler to deal with than CG. You don't even have to compile it separately as a library, just include the source files in your project. There are a few errors that pop up at first, but they're easy to track down and adjust.
Quote this message in a reply
⌘-R in Chief
Posts: 1,258
Joined: 2002.05
Post: #6
Speaking of which, and at the risk of thread-jacking, I had trouble getting SOIL to compile. Right out of the box it failed immediately with some error of not being able to create a directory in the tmp folder. If you can get a clean download of SOIL building AnotherJake, I'd love to know the steps.
Quote this message in a reply
Moderator
Posts: 3,574
Joined: 2003.06
Post: #7
Ah right, I forgot about that. This post I wrote a while back should help.

The other way is to drag the SOIL source and header files directly into your Xcode project and track down and fix the minor errors it'll produce. That's how I originally started using it for iOS.

Alternatively, I have two custom pre-built fat libs, one for iOS and one for MacOS, which I'd be happy to send you if you'd prefer to try those instead. I can send my makefile and sources too if you'd like, but it'd be fair of me to warn you that my makefile is pretty messy Rasp
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #8
thanks for help!
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #9
found another solution, i post it because i think it can be interesting and hopefully could help someone!
if there is no image can be an image mask then you can create one from that image however!
Code:
CGImageRef maskRef = [uiImage CGImage];
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
        CGImageGetHeight(maskRef),
        CGImageGetBitsPerComponent(maskRef),
        CGImageGetBitsPerPixel(maskRef),
        CGImageGetBytesPerRow(maskRef),
        CGImageGetDataProvider(maskRef), NULL, false);
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  save data of the app, and not loose them if i update the app sefiroths 2 3,212 Oct 16, 2012 12:01 PM
Last Post: sefiroths
  Crash during file save Coin 4 4,111 Mar 29, 2005 05:39 PM
Last Post: maaaaark