iphone Programming Glossary: cgcontextref
Retrieving a pixel alpha value for a UIImage http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiimage height width 4 bytesPerPixel 4 bytesPerRow bytesPerPixel width NSUInteger bitsPerComponent 8 CGContextRef context CGBitmapContextCreate rawData width height bitsPerComponent bytesPerRow colorSpace kCGImageAlphaPremultipliedLast..
How would I tint an image programatically on the iPhone? http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone the simplest thing that could possibly work. In your subclassed UIView void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetFillColor context CGColorGetComponents UIColor colorWithRed.. color you want along with the proper blending mode something like this void drawRect CGRect area CGContextRef context UIGraphicsGetCurrentContext CGContextSaveGState context Draw picture first CGContextDrawImage..
Resizing UIimages pulled from the Camera also ROTATES the UIimage? http://stackoverflow.com/questions/1260249/resizing-uiimages-pulled-from-the-camera-also-rotates-the-uiimage CGImageGetAlphaInfo imageRef if alphaInfo kCGImageAlphaNone alphaInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap CGBitmapContextCreate NULL width height CGImageGetBitsPerComponent imageRef 4 width CGImageGetColorSpace.. CGImageGetColorSpace imageRef if bitmapInfo kCGImageAlphaNone bitmapInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees CGImageGetColorSpace imageRef if bitmapInfo kCGImageAlphaNone bitmapInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown.. 180 UIImage rotate UIImage src UIImageOrientation orientation UIGraphicsBeginImageContext src.size CGContextRef context UIGraphicsGetCurrentContext if orientation UIImageOrientationRight CGContextRotateCTM context..
How to get the RGB values for a pixel on an image on the iphone http://stackoverflow.com/questions/144250/how-to-get-the-rgb-values-for-a-pixel-on-an-image-on-the-iphone subclass I declared instance variables size_t bytesPerRow size_t byteCount size_t pixelCount CGContextRef context CGColorSpaceRef colorSpace UInt8 pixelByteData A pointer to an array of RGBA bytes in memory..
Rounded UIView using CALayers - only some corners - How? http://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how code's not perfect but I'm sure you can tidy it up a little bit. static void addRoundedRectToPath CGContextRef context CGRect rect float radius int roundedCornerPosition all corners rounded CGContextMoveToPoint.. int w img.size.width int h img.size.height CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate NULL w h 8 4 w colorSpace kCGImageAlphaPremultipliedFirst CGContextBeginPath..
underline text in UIlabel http://stackoverflow.com/questions/2711297/underline-text-in-uilabel question You may subclass from UILabel and override drawRect method void drawRect CGRect rect CGContextRef ctx UIGraphicsGetCurrentContext CGContextSetRGBStrokeColor ctx 207.0f 255.0f 91.0f 255.0f 44.0f 255.0f..
How do I export UIImage array as a movie? http://stackoverflow.com/questions/3741323/how-do-i-export-uiimage-array-as-a-movie pxbuffer NSParameterAssert pxdata NULL CGColorSpaceRef rgbColorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate pxdata frameSize.width frameSize.height 8 4 frameSize.width rgbColorSpace..
Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints? http://stackoverflow.com/questions/3889634/fast-and-lean-pdf-viewer-for-iphone-ipad-ios-tips-and-hints and render it using the appropriate CTM. The code in void drawLayer CALayer layer inContext CGContextRef context is like CGAffineTransform currentCTM CGContextGetCTM context if currentCTM.a 1.0 baseImage Calculate..
How to customize the background/border colors of a grouped table view cell? http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view-cell All rights reserved. #import CustomCellBackgroundView.h static void addRoundedRectToPath CGContextRef context CGRect rect float ovalWidth float ovalHeight @implementation CustomCellBackgroundView @synthesize.. super initWithFrame frame Initialization code return self void drawRect CGRect rect Drawing code CGContextRef c UIGraphicsGetCurrentContext CGContextSetFillColorWithColor c fillColor CGColor CGContextSetStrokeColorWithColor.. dealloc borderColor release fillColor release super dealloc @end static void addRoundedRectToPath CGContextRef context CGRect rect float ovalWidth float ovalHeight float fw fh if ovalWidth 0 ovalHeight 0 1 CGContextAddRect..
iOS SDK - Programmatically generate a PDF file http://stackoverflow.com/questions/4362734/ios-sdk-programmatically-generate-a-pdf-file pageRect const char filename This code block sets up our PDF Context so that we can draw to it CGContextRef pdfContext CFStringRef path CFURLRef url CFMutableDictionaryRef myDictionary NULL Create a CFString..
Inner shadow effect on UIView layer? http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer then this is how on iOS adjust as needed In your drawRect method... CGRect bounds self bounds CGContextRef context UIGraphicsGetCurrentContext CGFloat radius 0.5f CGRectGetHeight bounds Create the visible path..
UIImagePickerController camera preview is portrait in landscape app http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-app format @ Invalid image orientation UIGraphicsBeginImageContext bounds.size CGContextRef context UIGraphicsGetCurrentContext if orient UIImageOrientationRight orient UIImageOrientationLeft..
iOS UIImagePickerController result image orientation after upload http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload Now we draw the underlying CGImage into a new context applying the transform calculated above. CGContextRef ctx CGBitmapContextCreate NULL self.size.width self.size.height CGImageGetBitsPerComponent self.CGImage..
How do I draw a line on the iPhone? http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone drawRect method in MyView.m here's some example code that draws a line void drawRect CGRect rect CGContextRef c UIGraphicsGetCurrentContext CGFloat red 4 1.0f 0.0f 0.0f 1.0f CGContextSetStrokeColor c red CGContextBeginPath..
Retrieving a pixel alpha value for a UIImage http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiimage colorSpace CGColorSpaceCreateDeviceRGB rawData malloc height width 4 bytesPerPixel 4 bytesPerRow bytesPerPixel width NSUInteger bitsPerComponent 8 CGContextRef context CGBitmapContextCreate rawData width height bitsPerComponent bytesPerRow colorSpace kCGImageAlphaPremultipliedLast kCGBitmapByteOrder32Big CGColorSpaceRelease..
How would I tint an image programatically on the iPhone? http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone For those of you just learning about Core Graphics here is the simplest thing that could possibly work. In your subclassed UIView void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetFillColor context CGColorGetComponents UIColor colorWithRed 0.5 green 0.5 blue 0 alpha 1 .CGColor don't make color.. image first then overlay it with a rectangle filled with the color you want along with the proper blending mode something like this void drawRect CGRect area CGContextRef context UIGraphicsGetCurrentContext CGContextSaveGState context Draw picture first CGContextDrawImage context self.frame self.image.CGImage Blend mode could be..
Resizing UIimages pulled from the Camera also ROTATES the UIimage? http://stackoverflow.com/questions/1260249/resizing-uiimages-pulled-from-the-camera-also-rotates-the-uiimage CGImageRef imageRef anImage CGImage CGImageAlphaInfo alphaInfo CGImageGetAlphaInfo imageRef if alphaInfo kCGImageAlphaNone alphaInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap CGBitmapContextCreate NULL width height CGImageGetBitsPerComponent imageRef 4 width CGImageGetColorSpace imageRef alphaInfo CGContextDrawImage bitmap CGRectMake.. imageRef CGColorSpaceRef colorSpaceInfo CGImageGetColorSpace imageRef if bitmapInfo kCGImageAlphaNone bitmapInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetWidth targetHeight..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees imageRef CGColorSpaceRef colorSpaceInfo CGImageGetColorSpace imageRef if bitmapInfo kCGImageAlphaNone bitmapInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetHeight targetWidth.. inline double radians double degrees return degrees M_PI 180 UIImage rotate UIImage src UIImageOrientation orientation UIGraphicsBeginImageContext src.size CGContextRef context UIGraphicsGetCurrentContext if orientation UIImageOrientationRight CGContextRotateCTM context radians 90 else if orientation UIImageOrientationLeft CGContextRotateCTM..
How to get the RGB values for a pixel on an image on the iphone http://stackoverflow.com/questions/144250/how-to-get-the-rgb-values-for-a-pixel-on-an-image-on-the-iphone constants #define RGBA 4 #define RGBA_8_BIT 8 In my UIImage subclass I declared instance variables size_t bytesPerRow size_t byteCount size_t pixelCount CGContextRef context CGColorSpaceRef colorSpace UInt8 pixelByteData A pointer to an array of RGBA bytes in memory RPVW_RGBAPixel pixelData The pixel struct with alpha in this..
Rounded UIView using CALayers - only some corners - How? http://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how rectangles with 2 or 3 rounded corners too if you want. The code's not perfect but I'm sure you can tidy it up a little bit. static void addRoundedRectToPath CGContextRef context CGRect rect float radius int roundedCornerPosition all corners rounded CGContextMoveToPoint context rect.origin.x rect.origin.y radius CGContextAddLineToPoint.. setImage UIImage img UIImage imageNamed @ my_image.png int w img.size.width int h img.size.height CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate NULL w h 8 4 w colorSpace kCGImageAlphaPremultipliedFirst CGContextBeginPath context CGRect rect CGRectMake 0 0 w h addRoundedRectToPath..
underline text in UIlabel http://stackoverflow.com/questions/2711297/underline-text-in-uilabel advance. iphone text uilabel underline share improve this question You may subclass from UILabel and override drawRect method void drawRect CGRect rect CGContextRef ctx UIGraphicsGetCurrentContext CGContextSetRGBStrokeColor ctx 207.0f 255.0f 91.0f 255.0f 44.0f 255.0f 1.0f RGBA CGContextSetLineWidth ctx 1.0f CGContextMoveToPoint..
How do I export UIImage array as a movie? http://stackoverflow.com/questions/3741323/how-do-i-export-uiimage-array-as-a-movie pxbuffer 0 void pxdata CVPixelBufferGetBaseAddress pxbuffer NSParameterAssert pxdata NULL CGColorSpaceRef rgbColorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate pxdata frameSize.width frameSize.height 8 4 frameSize.width rgbColorSpace kCGImageAlphaNoneSkipFirst NSParameterAssert context CGContextConcatCTM..
Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints? http://stackoverflow.com/questions/3889634/fast-and-lean-pdf-viewer-for-iphone-ipad-ios-tips-and-hints issued. Whenever the user start zooming I acquire the CGPDFPage and render it using the appropriate CTM. The code in void drawLayer CALayer layer inContext CGContextRef context is like CGAffineTransform currentCTM CGContextGetCTM context if currentCTM.a 1.0 baseImage Calculate ideal scale CGFloat scaleForWidth baseImage.size.width..
How to customize the background/border colors of a grouped table view cell? http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view-cell Created by Mike Akers on 11 21 08. Copyright 2008 __MyCompanyName__. All rights reserved. #import CustomCellBackgroundView.h static void addRoundedRectToPath CGContextRef context CGRect rect float ovalWidth float ovalHeight @implementation CustomCellBackgroundView @synthesize borderColor fillColor position BOOL isOpaque return.. isOpaque return NO id initWithFrame CGRect frame if self super initWithFrame frame Initialization code return self void drawRect CGRect rect Drawing code CGContextRef c UIGraphicsGetCurrentContext CGContextSetFillColorWithColor c fillColor CGColor CGContextSetStrokeColorWithColor c borderColor CGColor if position CustomCellBackgroundViewPositionTop.. c rect 10.0f 10.0f CGContextStrokePath c void dealloc borderColor release fillColor release super dealloc @end static void addRoundedRectToPath CGContextRef context CGRect rect float ovalWidth float ovalHeight float fw fh if ovalWidth 0 ovalHeight 0 1 CGContextAddRect context rect return CGContextSaveGState context..
iOS SDK - Programmatically generate a PDF file http://stackoverflow.com/questions/4362734/ios-sdk-programmatically-generate-a-pdf-file and other objects will be placed. void CreatePDFFile CGRect pageRect const char filename This code block sets up our PDF Context so that we can draw to it CGContextRef pdfContext CFStringRef path CFURLRef url CFMutableDictionaryRef myDictionary NULL Create a CFString from the filename we provide to this method when we call it..
Inner shadow effect on UIView layer? http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer an inner shadow using Core Graphics as per Costique suggestion then this is how on iOS adjust as needed In your drawRect method... CGRect bounds self bounds CGContextRef context UIGraphicsGetCurrentContext CGFloat radius 0.5f CGRectGetHeight bounds Create the visible path which will be the shape that gets the inner shadow In this..
UIImagePickerController camera preview is portrait in landscape app http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-app transform M_PI 2.0 break default NSException raise NSInternalInconsistencyException format @ Invalid image orientation UIGraphicsBeginImageContext bounds.size CGContextRef context UIGraphicsGetCurrentContext if orient UIImageOrientationRight orient UIImageOrientationLeft CGContextScaleCTM context scaleRatio scaleRatio CGContextTranslateCTM..
iOS UIImagePickerController result image orientation after upload http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload case UIImageOrientationLeft case UIImageOrientationRight break Now we draw the underlying CGImage into a new context applying the transform calculated above. CGContextRef ctx CGBitmapContextCreate NULL self.size.width self.size.height CGImageGetBitsPerComponent self.CGImage 0 CGImageGetColorSpace self.CGImage CGImageGetBitmapInfo..
How do I draw a line on the iPhone? http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone dropdown and choose MyView. Next you need to implement the drawRect method in MyView.m here's some example code that draws a line void drawRect CGRect rect CGContextRef c UIGraphicsGetCurrentContext CGFloat red 4 1.0f 0.0f 0.0f 1.0f CGContextSetStrokeColor c red CGContextBeginPath c CGContextMoveToPoint c 5.0f 5.0f CGContextAddLineToPoint..
Retrieving a pixel alpha value for a UIImage http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiimage rawData malloc height width 4 bytesPerPixel 4 bytesPerRow bytesPerPixel width NSUInteger bitsPerComponent 8 CGContextRef context CGBitmapContextCreate rawData width height bitsPerComponent bytesPerRow colorSpace kCGImageAlphaPremultipliedLast..
How would I tint an image programatically on the iPhone? http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone Core Graphics here is the simplest thing that could possibly work. In your subclassed UIView void drawRect CGRect rect CGContextRef context UIGraphicsGetCurrentContext CGContextSetFillColor context CGColorGetComponents UIColor colorWithRed 0.5 green 0.5.. filled with the color you want along with the proper blending mode something like this void drawRect CGRect area CGContextRef context UIGraphicsGetCurrentContext CGContextSaveGState context Draw picture first CGContextDrawImage context self.frame..
Resizing UIimages pulled from the Camera also ROTATES the UIimage? http://stackoverflow.com/questions/1260249/resizing-uiimages-pulled-from-the-camera-also-rotates-the-uiimage alphaInfo CGImageGetAlphaInfo imageRef if alphaInfo kCGImageAlphaNone alphaInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap CGBitmapContextCreate NULL width height CGImageGetBitsPerComponent imageRef 4 width CGImageGetColorSpace imageRef.. colorSpaceInfo CGImageGetColorSpace imageRef if bitmapInfo kCGImageAlphaNone bitmapInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees colorSpaceInfo CGImageGetColorSpace imageRef if bitmapInfo kCGImageAlphaNone bitmapInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate.. return degrees M_PI 180 UIImage rotate UIImage src UIImageOrientation orientation UIGraphicsBeginImageContext src.size CGContextRef context UIGraphicsGetCurrentContext if orientation UIImageOrientationRight CGContextRotateCTM context radians 90 else if..
How to get the RGB values for a pixel on an image on the iphone http://stackoverflow.com/questions/144250/how-to-get-the-rgb-values-for-a-pixel-on-an-image-on-the-iphone 8 In my UIImage subclass I declared instance variables size_t bytesPerRow size_t byteCount size_t pixelCount CGContextRef context CGColorSpaceRef colorSpace UInt8 pixelByteData A pointer to an array of RGBA bytes in memory RPVW_RGBAPixel pixelData..
Rounded UIView using CALayers - only some corners - How? http://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how too if you want. The code's not perfect but I'm sure you can tidy it up a little bit. static void addRoundedRectToPath CGContextRef context CGRect rect float radius int roundedCornerPosition all corners rounded CGContextMoveToPoint context rect.origin.x.. @ my_image.png int w img.size.width int h img.size.height CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate NULL w h 8 4 w colorSpace kCGImageAlphaPremultipliedFirst CGContextBeginPath context CGRect..
underline text in UIlabel http://stackoverflow.com/questions/2711297/underline-text-in-uilabel share improve this question You may subclass from UILabel and override drawRect method void drawRect CGRect rect CGContextRef ctx UIGraphicsGetCurrentContext CGContextSetRGBStrokeColor ctx 207.0f 255.0f 91.0f 255.0f 44.0f 255.0f 1.0f RGBA CGContextSetLineWidth..
How do I export UIImage array as a movie? http://stackoverflow.com/questions/3741323/how-do-i-export-uiimage-array-as-a-movie pxbuffer NSParameterAssert pxdata NULL CGColorSpaceRef rgbColorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate pxdata frameSize.width frameSize.height 8 4 frameSize.width rgbColorSpace kCGImageAlphaNoneSkipFirst..
Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints? http://stackoverflow.com/questions/3889634/fast-and-lean-pdf-viewer-for-iphone-ipad-ios-tips-and-hints I acquire the CGPDFPage and render it using the appropriate CTM. The code in void drawLayer CALayer layer inContext CGContextRef context is like CGAffineTransform currentCTM CGContextGetCTM context if currentCTM.a 1.0 baseImage Calculate ideal scale..
How to customize the background/border colors of a grouped table view cell? http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view-cell 2008 __MyCompanyName__. All rights reserved. #import CustomCellBackgroundView.h static void addRoundedRectToPath CGContextRef context CGRect rect float ovalWidth float ovalHeight @implementation CustomCellBackgroundView @synthesize borderColor.. CGRect frame if self super initWithFrame frame Initialization code return self void drawRect CGRect rect Drawing code CGContextRef c UIGraphicsGetCurrentContext CGContextSetFillColorWithColor c fillColor CGColor CGContextSetStrokeColorWithColor c borderColor.. c void dealloc borderColor release fillColor release super dealloc @end static void addRoundedRectToPath CGContextRef context CGRect rect float ovalWidth float ovalHeight float fw fh if ovalWidth 0 ovalHeight 0 1 CGContextAddRect context..
iOS SDK - Programmatically generate a PDF file http://stackoverflow.com/questions/4362734/ios-sdk-programmatically-generate-a-pdf-file CreatePDFFile CGRect pageRect const char filename This code block sets up our PDF Context so that we can draw to it CGContextRef pdfContext CFStringRef path CFURLRef url CFMutableDictionaryRef myDictionary NULL Create a CFString from the filename we..
Inner shadow effect on UIView layer? http://stackoverflow.com/questions/4431292/inner-shadow-effect-on-uiview-layer per Costique suggestion then this is how on iOS adjust as needed In your drawRect method... CGRect bounds self bounds CGContextRef context UIGraphicsGetCurrentContext CGFloat radius 0.5f CGRectGetHeight bounds Create the visible path which will be the..
UIImagePickerController camera preview is portrait in landscape app http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-app raise NSInternalInconsistencyException format @ Invalid image orientation UIGraphicsBeginImageContext bounds.size CGContextRef context UIGraphicsGetCurrentContext if orient UIImageOrientationRight orient UIImageOrientationLeft CGContextScaleCTM context..
iOS UIImagePickerController result image orientation after upload http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload break Now we draw the underlying CGImage into a new context applying the transform calculated above. CGContextRef ctx CGBitmapContextCreate NULL self.size.width self.size.height CGImageGetBitsPerComponent self.CGImage 0 CGImageGetColorSpace..
How do I draw a line on the iPhone? http://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone need to implement the drawRect method in MyView.m here's some example code that draws a line void drawRect CGRect rect CGContextRef c UIGraphicsGetCurrentContext CGFloat red 4 1.0f 0.0f 0.0f 1.0f CGContextSetStrokeColor c red CGContextBeginPath c CGContextMoveToPoint..
|