cgimage

Getting RGB pixel data from CGImage

允我心安 提交于 2019-11-27 06:23:46
I am trying to access pixel data from a CGImage. I want to be able to access the RGB values as integers. I think I am nearly there with this code: UIImage* theImage = [UIImage imageNamed:@"rgb.png"]; CGImageRef cgImageRef = CGImageRetain(theImage.CGImage); CFDataRef* imageData = CGDataProviderCopyData(CGImageGetDataProvider(cgImageRef)); NSLog(@"the data = %@", imageData); This then logs: the data = <010002fe fffdff02 0200fe04 0003fc> The image is a 5x1 png containing a black, white, red, green and blue pixel in that order. I don't really understand what I am looking at here. How can I get an

Generating custom thumbnail from ALAssetRepresentation

心不动则不痛 提交于 2019-11-27 01:23:09
问题 My main problem is i need to obtain a thumbnail for an ALAsset object. I tried a lot of solutions and searched stack overflow for days, all the solutions i found are not working for me due to these constraint: I can't use the default thumbnail because it's too little; I can't use the fullScreen or fullResolution image because i have a lot of images on screen; I can't use UIImage or UIImageView for resizing because those loads the fullResolution image I can't load the image in memory, i'm

CGImage/UIImage lazily loading on UI thread causes stutter

风格不统一 提交于 2019-11-27 00:06:54
My program displays a horizontal scrolling surface tiled with UIImageViews from left to right. Code runs on the UI thread to ensure that newly-visible UIImageViews have a freshly loaded UIImage assigned to them. The loading happens on a background thread. Everything works almost fine, except there is a stutter as each image becomes visible. At first I thought my background worker was locking something in the UI thread. I spent a lot of time looking at it and eventually realized that the UIImage is doing some extra lazy processing on the UI thread when it first becomes visible. This puzzles me,

iPhone CGContextRef CGBitmapContextCreate unsupported parameter combination

ε祈祈猫儿з 提交于 2019-11-26 23:21:45
问题 In my application I need to resize and crop some images, stored locally and online. I am using Trevor Harmon's tutorial which implements UIImage+Resize . On my iPhone 4(iOS 4.3.1) everything works OK, I have no problems. But on my iPhone 3G (iOS 3.2) the resizing and crop methods are not working for any picture (the locally stored ones are PNGs). This is the console output: Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter

CGImage from byte array

放肆的年华 提交于 2019-11-26 20:18:30
问题 Loading a CGImage or NSImage from a file using a standard image format (jpeg, gif, png et.) is all very simple. However, I now need to create a CGImage from an array in bytes in memory generated using libfreetype. Its really easy to create OpenGL textures from an array of formatted bytes, and I can see how to create a CGBitmapContext to write to. But I can't seem to find an easy way to create a CGImage from a raw pixel array. 回答1: You can create a CGDataProvider , and let CG request the

Rotating a CGImage

浪子不回头ぞ 提交于 2019-11-26 19:01:58
I have a UIImage that I'm getting from a UIImagePickerController. When I receive the image from the - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info method I put it straight into a UIImageView for preview and give the user the option to either save or discard the image. When the user selects the save option the application get the png data for the image and saves it to it's documents directory. But what happens under one of the 2 possible device orientations (landscape only) is that the image is saved upside down (more

Pixel Array to UIImage in Swift

守給你的承諾、 提交于 2019-11-26 16:36:42
问题 I've been trying to figure out how to convert an array of rgb pixel data to a UIImage in Swift. I'm keeping the rgb data per pixel in a simple struct: public struct PixelData { var a: Int var r: Int var g: Int var b: Int } I've made my way to the following function, but the resulting image is incorrect: func imageFromARGB32Bitmap(pixels:[PixelData], width: Int, height: Int)-> UIImage { let rgbColorSpace = CGColorSpaceCreateDeviceRGB() let bitmapInfo:CGBitmapInfo = CGBitmapInfo

Get pixel data as array from UIImage/CGImage in swift

我只是一个虾纸丫 提交于 2019-11-26 16:34:17
问题 I have an app so far that allows the user to free draw (like a sketch pad) on a UIImageView element. I want to get the raw RGB pixel data (as 0 to 255 integer values) as a multidimensional array so I can feed it into a machine learning algorithm . Or is there some other way I can send the raw image data over to separate C++ function? Is there an easy way to do this in Swift? 回答1: In Swift 3 and Swift 4, using Core Graphics, it is quite easy to do what you want: extension UIImage { func

Getting RGB pixel data from CGImage

扶醉桌前 提交于 2019-11-26 11:58:50
问题 I am trying to access pixel data from a CGImage. I want to be able to access the RGB values as integers. I think I am nearly there with this code: UIImage* theImage = [UIImage imageNamed:@\"rgb.png\"]; CGImageRef cgImageRef = CGImageRetain(theImage.CGImage); CFDataRef* imageData = CGDataProviderCopyData(CGImageGetDataProvider(cgImageRef)); NSLog(@\"the data = %@\", imageData); This then logs: the data = <010002fe fffdff02 0200fe04 0003fc> The image is a 5x1 png containing a black, white, red,

Saving CGImageRef to a png file?

非 Y 不嫁゛ 提交于 2019-11-26 10:31:40
问题 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! 回答1: Create a CGImageDestination , passing kUTTypePNG as the type of file to create. Add the image, then finalize the destination. 回答2: Using CGImageDestination and passing kUTTypePNG is the correct approach. Here's a quick snippet: @import MobileCoreServices; // or `@import CoreServices;` on Mac @import ImageIO; BOOL