iphone Programming Glossary: cgbitmapcontextcreate
Retrieving a pixel alpha value for a UIImage http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiimage bytesPerPixel 4 bytesPerRow bytesPerPixel width NSUInteger bitsPerComponent 8 CGContextRef context CGBitmapContextCreate rawData width height bitsPerComponent bytesPerRow colorSpace kCGImageAlphaPremultipliedLast kCGBitmapByteOrder32Big..
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 imageRef if alphaInfo kCGImageAlphaNone alphaInfo kCGImageAlphaNoneSkipLast CGContextRef bitmap CGBitmapContextCreate NULL width height CGImageGetBitsPerComponent imageRef 4 width CGImageGetColorSpace imageRef alphaInfo.. imageRef alphaInfo CGContextDrawImage bitmap CGRectMake 0 0 width height imageRef CGImageRef ref CGBitmapContextCreateImage bitmap UIImage result UIImage imageWithCGImage ref CGContextRelease bitmap CGImageRelease ref return.. UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetWidth targetHeight CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo..
Convert image to grayscale http://stackoverflow.com/questions/1298867/convert-image-to-grayscale CGColorSpaceCreateDeviceRGB unsigned char rawData malloc height width 4 CGContextRef context CGBitmapContextCreate rawData width height bitsPerComponent bytesPerRow colorSpace kCGImageAlphaPremultipliedLast kCGBitmapByteOrder32Big.. sizeof uint32_t CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate rgbImage m_width m_height 8 m_width 4 colorSpace kCGBitmapByteOrder32Little kCGImageAlphaNoneSkipLast.. result i 4 2 val result i 4 3 val create a UIImage colorSpace CGColorSpaceCreateDeviceRGB context CGBitmapContextCreate result m_width m_height 8 m_width sizeof uint32_t colorSpace kCGBitmapByteOrder32Little kCGImageAlphaNoneSkipLast..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees to do this. I set a target size as the current size of the UIImage but I get an error Error CGBitmapContextCreate invalid data bytes row should be at least 1708 for 8 integer bits component 3 components kCGImageAlphaPremultipliedLast... UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetHeight targetWidth CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo.. imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo else bitmap CGBitmapContextCreate NULL targetWidth targetHeight CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo..
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 bits per component. The source image format will be converted to the format specified here by CGBitmapContextCreate. self setContext CGBitmapContextCreate void pixelData self.size.width self.size.height RGBA_8_BIT.. format will be converted to the format specified here by CGBitmapContextCreate. self setContext CGBitmapContextCreate void pixelData self.size.width self.size.height RGBA_8_BIT bytesPerRow colorSpace kCGImageAlphaPremultipliedLast..
Rounded UIView using CALayers - only some corners - How? http://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how int h img.size.height CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate NULL w h 8 4 w colorSpace kCGImageAlphaPremultipliedFirst CGContextBeginPath context CGRect rect CGRectMake.. context CGContextClip context CGContextDrawImage context rect img.CGImage CGImageRef imageMasked CGBitmapContextCreateImage context CGContextRelease context CGColorSpaceRelease colorSpace img release return UIImage imageWithCGImage..
How do I export UIImage array as a movie? http://stackoverflow.com/questions/3741323/how-do-i-export-uiimage-array-as-a-movie pxdata NULL CGColorSpaceRef rgbColorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate pxdata frameSize.width frameSize.height 8 4 frameSize.width rgbColorSpace kCGImageAlphaNoneSkipFirst..
Round two corners in UIView http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview CGColorSpaceCreateDeviceRGB create a bitmap graphics context the size of the image context CGBitmapContextCreate NULL rect.size.width rect.size.height 8 0 colorSpace kCGImageAlphaPremultipliedLast free the rgb colorspace.. of the main view bitmap content and then release that bitmap context CGImageRef bitmapContext CGBitmapContextCreateImage context CGContextRelease context convert the finished resized image to a UIImage UIImage theImage..
iOS UIImagePickerController result image orientation after upload http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload 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 break And now we just create a new UIImage from the drawing context CGImageRef cgimg CGBitmapContextCreateImage ctx UIImage img UIImage imageWithCGImage cgimg CGContextRelease ctx CGImageRelease cgimg return..
Retrieving a pixel alpha value for a UIImage http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiimage 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 colorSpace 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 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 0 0 width height imageRef.. imageRef 4 width CGImageGetColorSpace imageRef alphaInfo CGContextDrawImage bitmap CGRectMake 0 0 width height imageRef CGImageRef ref CGBitmapContextCreateImage bitmap UIImage result UIImage imageWithCGImage ref CGContextRelease bitmap CGImageRelease ref return result QUESTION How do I RESIZE a UIImage pulled from.. kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetWidth targetHeight CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo else bitmap CGBitmapContextCreate NULL..
Convert image to grayscale http://stackoverflow.com/questions/1298867/convert-image-to-grayscale bytesPerRow bytesPerPixel width CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB unsigned char rawData malloc height width 4 CGContextRef context CGBitmapContextCreate rawData width height bitsPerComponent bytesPerRow colorSpace kCGImageAlphaPremultipliedLast kCGBitmapByteOrder32Big CGColorSpaceRelease colorSpace CGContextDrawImage.. i.size.height uint32_t rgbImage uint32_t malloc m_width m_height sizeof uint32_t CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate rgbImage m_width m_height 8 m_width 4 colorSpace kCGBitmapByteOrder32Little kCGImageAlphaNoneSkipLast CGContextSetInterpolationQuality context kCGInterpolationHigh.. i result i 4 0 int val m_imageData i result i 4 1 val result i 4 2 val result i 4 3 val create a UIImage colorSpace CGColorSpaceCreateDeviceRGB context CGBitmapContextCreate result m_width m_height 8 m_width sizeof uint32_t colorSpace kCGBitmapByteOrder32Little kCGImageAlphaNoneSkipLast CGImageRef image CGBitmapContextCreateImage context..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees block of code shown below originally intended to resize a UIImage to do this. I set a target size as the current size of the UIImage but I get an error Error CGBitmapContextCreate invalid data bytes row should be at least 1708 for 8 integer bits component 3 components kCGImageAlphaPremultipliedLast. I don't get an error whenever I provide.. kCGImageAlphaNoneSkipLast CGContextRef bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetHeight targetWidth CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo else bitmap CGBitmapContextCreate NULL.. CGBitmapContextCreate NULL targetHeight targetWidth CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo else bitmap CGBitmapContextCreate NULL targetWidth targetHeight CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo if sourceImage.imageOrientation UIImageOrientationRight..
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 return nil Create the bitmap context. Pre multiplied RGBA 8 bits per component. The source image format will be converted to the format specified here by CGBitmapContextCreate. self setContext CGBitmapContextCreate void pixelData self.size.width self.size.height RGBA_8_BIT bytesPerRow colorSpace kCGImageAlphaPremultipliedLast.. Pre multiplied RGBA 8 bits per component. The source image format will be converted to the format specified here by CGBitmapContextCreate. self setContext CGBitmapContextCreate void pixelData self.size.width self.size.height RGBA_8_BIT bytesPerRow colorSpace kCGImageAlphaPremultipliedLast Make sure we have our context..
Rounded UIView using CALayers - only some corners - How? http://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how 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 context rect 50 1 CGContextClosePath.. w h addRoundedRectToPath context rect 50 1 CGContextClosePath context CGContextClip context CGContextDrawImage context rect img.CGImage CGImageRef imageMasked CGBitmapContextCreateImage context CGContextRelease context CGColorSpaceRelease colorSpace img release return UIImage imageWithCGImage imageMasked Don't forget that you'll need to get..
How do I export UIImage array as a movie? http://stackoverflow.com/questions/3741323/how-do-i-export-uiimage-array-as-a-movie 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 context frameTransform..
Round two corners in UIView http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview CGContextRef context CGColorSpaceRef colorSpace colorSpace CGColorSpaceCreateDeviceRGB create a bitmap graphics context the size of the image context CGBitmapContextCreate NULL rect.size.width rect.size.height 8 0 colorSpace kCGImageAlphaPremultipliedLast free the rgb colorspace CGColorSpaceRelease colorSpace if context NULL return.. context CGContextDrawPath context kCGPathFill Create CGImageRef of the main view bitmap content and then release that bitmap context CGImageRef bitmapContext CGBitmapContextCreateImage context CGContextRelease context convert the finished resized image to a UIImage UIImage theImage UIImage imageWithCGImage bitmapContext image is retained..
iOS UIImagePickerController result image orientation after upload http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload 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 self.CGImage CGContextConcatCTM..
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 kCGBitmapByteOrder32Big CGColorSpaceRelease..
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 imageRef alphaInfo CGContextDrawImage.. CGImageGetColorSpace imageRef alphaInfo CGContextDrawImage bitmap CGRectMake 0 0 width height imageRef CGImageRef ref CGBitmapContextCreateImage bitmap UIImage result UIImage imageWithCGImage ref CGContextRelease bitmap CGImageRelease ref return result QUESTION.. bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetWidth targetHeight CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo..
Can I edit the pixels of the UIImage's property CGImage http://stackoverflow.com/questions/1281210/can-i-edit-the-pixels-of-the-uiimages-property-cgimage a way to do it. Write a class with those method void preProcess UIImage srcImage m_Context ... Created by calling CGBitmapContextCreate ... ... CGContextDrawImage m_Context rect srcImage.CGImage m_Bits unsigned char CGBitmapContextGetData mContext void postProcess.. free m_Bits UIImage doProcess CGPoint pt just a example unsigned char ppxl m_Bits ... do something... CGImageRef imRef CGBitmapContextCreateImage mContext return UIImage imageWithCGImage imRef And preProcess and postProcess are called just once. iphone cocoa cocoa..
Convert image to grayscale http://stackoverflow.com/questions/1298867/convert-image-to-grayscale colorSpace CGColorSpaceCreateDeviceRGB unsigned char rawData malloc height width 4 CGContextRef context CGBitmapContextCreate rawData width height bitsPerComponent bytesPerRow colorSpace kCGImageAlphaPremultipliedLast kCGBitmapByteOrder32Big CGColorSpaceRelease.. malloc m_width m_height sizeof uint32_t CGColorSpaceRef colorSpace CGColorSpaceCreateDeviceRGB CGContextRef context CGBitmapContextCreate rgbImage m_width m_height 8 m_width 4 colorSpace kCGBitmapByteOrder32Little kCGImageAlphaNoneSkipLast CGContextSetInterpolationQuality.. i result i 4 1 val result i 4 2 val result i 4 3 val create a UIImage colorSpace CGColorSpaceCreateDeviceRGB context CGBitmapContextCreate result m_width m_height 8 m_width sizeof uint32_t colorSpace kCGBitmapByteOrder32Little kCGImageAlphaNoneSkipLast CGImageRef..
How to Rotate a UIImage 90 degrees? http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees to resize a UIImage to do this. I set a target size as the current size of the UIImage but I get an error Error CGBitmapContextCreate invalid data bytes row should be at least 1708 for 8 integer bits component 3 components kCGImageAlphaPremultipliedLast... bitmap if sourceImage.imageOrientation UIImageOrientationUp sourceImage.imageOrientation UIImageOrientationDown bitmap CGBitmapContextCreate NULL targetHeight targetWidth CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo.. targetWidth CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo else bitmap CGBitmapContextCreate NULL targetWidth targetHeight CGImageGetBitsPerComponent imageRef CGImageGetBytesPerRow imageRef colorSpaceInfo bitmapInfo..
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 Pre multiplied RGBA 8 bits per component. The source image format will be converted to the format specified here by CGBitmapContextCreate. self setContext CGBitmapContextCreate void pixelData self.size.width self.size.height RGBA_8_BIT bytesPerRow.. The source image format will be converted to the format specified here by CGBitmapContextCreate. self setContext CGBitmapContextCreate void pixelData self.size.width self.size.height RGBA_8_BIT bytesPerRow colorSpace kCGImageAlphaPremultipliedLast..
CGImage/UIImage lazily loading on UI thread causes stutter http://stackoverflow.com/questions/1815476/cgimage-uiimage-lazily-loading-on-ui-thread-causes-stutter thread only. They are probably the source of your trouble. You can replace UIGraphicsBeginImageContext with a call to CGBitmapContextCreate it's a little more involved you need to create a color space figure out the right sized buffer to create and allocate it..
Rounded UIView using CALayers - only some corners - How? http://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how 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.. 1 CGContextClosePath context CGContextClip context CGContextDrawImage context rect img.CGImage CGImageRef imageMasked CGBitmapContextCreateImage context CGContextRelease context CGColorSpaceRelease colorSpace img release return UIImage imageWithCGImage imageMasked..
UIImage rounded corners http://stackoverflow.com/questions/262156/uiimage-rounded-corners colorSpace CGColorSpaceCreateDeviceRGB create a bitmap graphics context the size of the image mainViewContentContext CGBitmapContextCreate NULL targetSize.width targetSize.height 8 0 colorSpace kCGImageAlphaPremultipliedLast free the rgb colorspace CGColorSpaceRelease.. of the main view bitmap content and then release that bitmap context CGImageRef mainViewContentBitmapContext CGBitmapContextCreateImage mainViewContentContext CGContextRelease mainViewContentContext CGImageRef maskImage UIImage imageNamed @ Mask.png CGImage..
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 NSParameterAssert context..
Round two corners in UIView http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview colorSpace colorSpace CGColorSpaceCreateDeviceRGB create a bitmap graphics context the size of the image context CGBitmapContextCreate NULL rect.size.width rect.size.height 8 0 colorSpace kCGImageAlphaPremultipliedLast free the rgb colorspace CGColorSpaceRelease.. Create CGImageRef of the main view bitmap content and then release that bitmap context CGImageRef bitmapContext CGBitmapContextCreateImage context CGContextRelease context convert the finished resized image to a UIImage UIImage theImage UIImage imageWithCGImage..
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 self.CGImage .. self.size.height self.CGImage break And now we just create a new UIImage from the drawing context CGImageRef cgimg CGBitmapContextCreateImage ctx UIImage img UIImage imageWithCGImage cgimg CGContextRelease ctx CGImageRelease cgimg return img @end share improve..
How to make one color transparent on a UIImage? http://stackoverflow.com/questions/633722/how-to-make-one-color-transparent-on-a-uiimage kCGBitmapByteOrderDefault CGColorRenderingIntent renderingIntent kCGRenderingIntentDefault CGContextRef cgctx CGBitmapContextCreate bufferdata mWidth mHeight 8 mWidth 4 colorSpaceRef kCGImageAlphaPremultipliedFirst CGRect rect 0 0 mWidth mHeight CGContextDrawImage..
|