cgimage

Producing CCITT compressed TIFF from CGImage

I have a CGImage (core graphics, C/C++). It's grayscale. Well, originally it was B/W, but the CGImage may be RGB. That shouldn't matter. I want to create a CCITT-Group 4 TIFF. I can create an LZW TIFF (grayscale or color) via creating a destination with the correct dictionary and adding the image in. No problem. However, there doesn't...

Most efficent way to create a CALayer with an image in it?

I am wondering what the most efficient way is to make a CALayer with an image in it. I know you can load a UIImage and then call [image CGImage] but is this the best way of going about it? As far as I can tell from Apple's documentation this is the only way you can do it. ...

Convert image to grayscale

Hi, I am trying to convert an image into grayscale in the following way: #define bytesPerPixel 4 #define bitsPerComponent 8 -(unsigned char*) getBytesForImage: (UIImage*)pImage { CGImageRef image = [pImage CGImage]; NSUInteger width = CGImageGetWidth(image); NSUInteger height = CGImageGetHeight(image); NSUInteger byte...

Saving CGImageRef to a png file?

Hi, in my Cocoa application, I load a .jpg file from disk, manipulate it. Now it needs to be written to disk as a .png file. How can you do that? Thanks for your help! ...

How to add a CGImageRef to a NSDictionary?

I have a CGImageRef variable and a CGRect (so no pointers) and I need to add it to an NSDictionary. Like an NSArray, NSDictionary-s only accept pointers. How can you add an CGImageRef or an CGRect anyway? ...

CGImageRef resize without scaling

Hi, I have a CGImageRef that is lets say 35x35. I'm using it and a mask to create another image, but the mask is 50x50. CGImageRef subImage = CGImageCreateWithImageInRect(imageRef, CGRectMake(x, y, 35, 35)); CGImageRef xMaskedImage = CGImageCreateWithMask(subImage, mask); Apparently this stretches the subImage out to be 50x50, but w...

iPhone: How to change the color of an image

Hi, I have a small image from a database and the image's average color need to be altered slightly. It's a CGImageRef and I thought of creating a CGContext, drawing the image to this context, then subsequently changing the bitmap data somehow and finally rendering it. But how can I alter the color information? Thanks for your help! ...

How can I iterate on RGBA of EACH pixel in a bitmap context?

How do I iterate on EACH PIXEL in a bitmap context? I found some source that seems to be attempting to do this but it is somehow flawed. Can someone tell me how to fix this code so that I can iterate on the RGBA of each pixel? -(UIImage*)modifyPixels:(UIImage*)originalImage { NSData* pixelData = (NSData*)CGDataProviderCopyData(CGImageG...

iPhone: CGBitmapContextCreateImage() only works in Simulator

Hi, I created an app which creates an image by using CoreGraphics. The images appears on the screen when using the iPhone Simulator (OS 3.1 beta3) but not when I run the application on the device. What could be the cause of this? The code snipped which extracts the image from the context and puts it in an image view looks like this: ...

How do I create a mutable array of CGImageRefs?

I want to keep a mutable collection of CGImageRefs. Do I need to wrap them in NSValue, and if so how do I wrap and unwrap them properly? Can I get away with using a C array? If so how do I construct it and how do I add elements to it later? Is it significantly more costly to use UIImages instead of CGImageRefs as the elements of the coll...

iPhone - UIImage Leak, CGBitmapContextCreateImage Leak

Alright I am having a world of difficulty tracking down this memory leak. When running this script I do not see any memory leaking, but my objectalloc is climbing. Instruments points to CGBitmapContextCreateImage > create_bitmap_data_provider > malloc, this takes up 60% of my objectalloc. This code is called several times with a NSTim...

Does CGImageRelease() free UIImage's memory?

Hi, I have the following code: UIImage *originalImage; CGImageRef cgImage = [originalImage CGImage]; I know that CGImage is a read-only property of UIImage class. Does the line CGImageRelease(cgImage) free originalImage's memory? I'm tracing down a bug in my program and this line seems to be a hot candidate if I'm trying to acces...

takepicture() vs UIGetScreenImage()

Hello all. I'm trying to build a QRCodeReader for a project our research group is working on for the iPhone. After much research I found the program called QuickMark. This program scans automatically for QRCodes. What it appears to do is load the UIImagePicker and read off data from the camera. I suspect it is using UIGetScreenImage and ...

UIImage Memory problems becoz of caching

Hi, I googled for the memory issue associated with UIImage and came across many threads talking about the problem but no real help or solution. I know when we use -imageNamed: the object is being cached so it's better to use initWithData:. When we use drawRect: and UIGraphicsGetImageFromCurrentImageContext(), does the image goes to cac...

How do I create a CGImage with RGB data?

Can anyone show me a clear example of how to use CGImageRef CGImageCreate ( size_t width, size_t height, size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow, CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo, CGDataProviderRef provider, const CGFloat decode[], bool shouldInterpolate, CGCo...

CGImageRef and drawing layers

I have this code: CGDataProviderRef provider = CGDataProviderCreateWithFilename([myFile UTF8String]); CGImageRef img = CGImageCreateWithJPEGDataProvider(provider, NULL, true, kCGRenderingIntentDefault); Later I load that CGImageRef in a UIImage this way: UIImage *uiImage = [[UIImage alloc] initWithCGImage:destImage]; I'd like to dr...

UIImage within Thread not being Released / Overwritten

This appears to be the the classic method for scanning images from the iPhone. I have a thread that is dispatched from the main thread to go and scan for Codes. It essentially creates a new UIImage each time then removes it. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; { while (![thread isCancelled]) { #ifdef DE...

CGImage create orientation less image.

Hi, I want to display an image on the display. Input images may be orientated. I can't go with CIImages as the images are raw images and it will take up huge amount of CPU and memory. So i tried out with the CGImage, With thumbnail creation it works fine, but with image creation it doesn't provide the orientation less image. NSDict...

iPhone SDK: using CGImageCreate with an indexedColorSpace adds map to each pixel row

I am using a color map lookup table in my indexed color space. When I use CGImageCreate to create the CGImage, then create a UIImage, I get an extra COLUMN of pixels in the first 32 bits (4 pixels) of every pixel row... which causes the image to shift right by 4 pixels. It looks like the color map is being written to the first 32 bits of...

Thread Safety Of Custom Sequential CGDataProvider

When creating a custom sequential CGDataProvder to render a custom image format you specify the CGDataProviderSequentialCallbacks that should be used. While doing some optimization work to improve the speed of my sequential CGDataProvider I started to wonder about the thread safety of those callbacks. Let's assume I have created a si...