core-graphics

Converting a CGLayer to a *transparent* UIImage and PNG file in CoreGraphics iphone

Hi all, I've been making a simple painting app for the iphone. I'm trying to convert the drawn image to a transparent PNG (I don't want a white background). I'd also like to get a UIImage representation to use in a UIImageView. Currently, I respond to touch events and draw paths to a CGLayer which is then drawn to my views context. I h...

How do I make UILabel display outlined text?

All I want is a one pixel black border around my white UILabel text. I got as far as subclassing UILabel with the code below, which I clumsily cobbled together from a few tangentially related online examples. And it works but it's very, very slow (except on the simulator) and I couldn't get it to center the text vertically either (so I...

How to mask a UIImage so that white becomes transparent on iphone?

Hi All, I have a UIImage (generated by a user drawing) that has a white background. I'd like to make the white portions of this image transparent. I'd also like to save this to a PNG file. I've looked around on forums but can't figure out how to mask the image correctly. Has anyone tried this before? Thanks. ...

Can UILabel's drawTextInRect method be overridden to change the size of UILabel's text?

Apple's documentation for drawTextInRect seems to indicate this is possible: "By the time this method is called, the current graphics context is already configured with the default environment and text color for drawing. In your overridden method, you can configure the current context further and then invoke super to do the actual draw...

How to create a UIImage from the current graphics context?

I'd like to create a UIImage object from the current graphics context. More specifically, my use case is a view that the user can draw lines on. They may draw incrementally. After they are done, I'd like to create a UIImage to represent their drawing. Here is what drawRect: looks like for me now: - (void)drawRect:(CGRect)rect { CGCo...

How can I add the alpha channel of image A to the alpha channel of image B?

I have two images. One of them is just plain white and has some areas with alpha transparency. It is intended to be a mask for making another image transparent. The other image, full colored and also PNG, has no alpha applied anywhere. So I want to add the alpha values of the mask image to the alpha values of the other. Both images have...

Any idea why this image masking code does not work?

I have this code to mask an image. Basically, I only work with PNG images. So I have a 300x400 PNG image with 24bits of color (PNG-24). I am not sure if it also has an alpha channel. But there's no transparency in it. Then, there is the image mask which is PNG-8bit without alpha channel. It is just black, grayscale and white. I create...

Vertical flip of CGContext

I have a UIView that I am trying to render into a UIImage using [CALayer renderInContext:]. However, I find that the resultant image is flipped vertically. I kind of expect this due to the different coordinate systems. However, I then try and flip the context back to normal with an affine transform - but it doesn't have any effect: CGAf...

Obtain a CGContextRef of NSView outside of drawRect ?

I need to get CGContextRef of NSView object. It won't be so bad if I knew how. In Carbon this thing was done like this: CGContextRef cgref = (libvlc_drawable_t)GetWindowPort(HIViewGetWindow((OpaqueControlRef*)hiViewRef)); Obviously it can be done by subclassing NSView (or it's subclass) and catching it in it's drawRect, but that's to...

How do I free these resources in my iPhone application?

Okay, I have an app that tells me what color of pixel I touched by reading the screen (like a screenshot) after each touch. To retrieve the pixels, I use a method similar to that appearing here. But it seems that after each touch, the image data is still being held on to (and not to mention saving hundreds of unwanted screenshots in my p...

How to color an image having shapes?

I know its possible with boundary fill, but have tried everything in Objective C and I'm still not successful. Any help with code will be highly appreciated. This code returns the color of the touched pixel: unsigned char* data = CGBitmapContextGetData (cgctx); if (data != NULL) { offset = 4*((w*round(point.y))+round(point.x)); ...

How can I change the saturation of an UIImage?

I have an UIImage and want to shift it's saturation about +10%. Are there standard methods or functions that can be used for this? ...

How to flip coordinates when drawing in context?

I create a context from an UIImage, and then I draw into it with CGContextDrawImage(bitmapContext, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), oImageRef); the image appears upside-down due to the flipped coordinate system in quartz. How can I fix that? ...

How to create a CGGradient for my UIView subclass ?

Does anyone know how to create a CGGradient that will fill my view, my current code is this and it fill the UIView with a red rectangle I want to have a gradient (from black to gray for instance) instead of the rect : - (void)drawRect:(CGRect)rect { CGContextRef context=UIGraphicsGetCurrentContext(); CGRect r; r.origin.x=00...

Any techniques to draw path animated?

Is there a way to simulate handwriting using quartz? I mean there is a path between points A, B and C. I want path to come out of point A and go animated to point B and then C. What comes to mind is two options to do it: Ugly- Create path then mask it and move mask around to reveal a path. Takes a lot of time to create and unrelia...

Scaling not as smooth in 3.0 as in 2.x

I have a CATiledLayer backed UIView that is added to UIScrollView and it is returned as view to be scaled in response to -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView delegate method. Now the problem is that scaling on a scale falling between the 2x steps provided by CATiledLayer (like for example 1.333) results in v...

Is there a non-deprecated raster graphics framework for Mac OS X?

I am looking for a raster graphics framework for Mac OS X. Specifically, I want some kind of view that I can manipulate (at least conceptually) like a matrix of pixels. My program will generate the pixel data programmatically. QuickDraw fits that description nicely, but is deprecated. As far as I can tell, there is nothing equivalent in...

Reduce Core-Graphics memory consumption on iphone

I am writing a program which redraws a graph every so often. Unfortunately it seems that for some reason core graphics does not seem to release the previous graphic so I run into memory problems fast. How can I force it to release memory at the end of each draw? Not that this is not a memory leak as the memory does get released when I l...

Rounded UIView with Shadow?

So using this link: http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview And this link: http://iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html I came upon this implementation: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSav...

Cocoa bindings and KVC with CGColorRef

I'm trying to bind a CGColorRef on one of my objects to the "shadowColor" property of a CALayer. Unfortunately, I haven't been able to figure this out - it's probably something really simple! The CGColorRef is implemented as a property: @property (readwrite) CGColorRef labelShadowColor; My binding is straight forward too: [aLayer bi...