cgimage

color balance on the iPhone

China☆狼群 提交于 2019-12-06 13:33:36
I am taking an image, loading it via the screen context, and changing it pixel by pixel. I have a number of different filters that I am applying to the images, but the last thing I need to do is shift the color balance (similar to Photoshop) to make the red more cyan. The code below shows how I am taking the image, getting the data, and going through the r/g/b values pixel by pixel: CGImageRef sourceImage = theImage.image.CGImage; CFDataRef theData; theData = CGDataProviderCopyData(CGImageGetDataProvider(sourceImage)); UInt8 *pixelData = (UInt8 *) CFDataGetBytePtr(theData); int dataLength =

Producing CCITT compressed TIFF from CGImage

百般思念 提交于 2019-12-06 07:27:19
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 seem to be an equivalent kCGImagePropertyTIFFCompression value to represent CCITT-4. It should be 4, but that produces uncompressed. I have a manual CCITT compression routine, so if I can get the binary (1 bit per pixel) data, I'm set. But I can't seem to get 1

Dictionary now gives error 'not convertible to BooleanLiteralConvertible' since updating to Swift 1.2

痴心易碎 提交于 2019-12-06 05:45:32
问题 I'm was just getting my head around Swift - then came Swift 1.2 (breaking my working code)! I have a function based on the code sample from NSHipster - CGImageSourceCreateThumbnailAtIndex. My previously working code is: import ImageIO func processImage(jpgImagePath: String, thumbSize: CGSize) { if let path = NSBundle.mainBundle().pathForResource(jpgImagePath, ofType: "") { if let imageURL = NSURL(fileURLWithPath: path) { if let imageSource = CGImageSourceCreateWithURL(imageURL, nil) { let

Getting NSData from UIImage object that contains CGImage

拜拜、爱过 提交于 2019-12-06 05:44:21
In order to upload an image file to my server, I need to get it's NSData. I am having trouble doing this right now, because my UIImage contains a CGImage. Let me show you how I am doing things. When a user takes a photo, this is what I do with the captured photo: NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; UIImage *image = [[UIImage alloc]initWithData:imageData]; _subLayer = [CALayer layer]; image = [self selfieCorrection:image]; image = [self rotate:image andOrientation:image.imageOrientation]; CGRect cropRectFinal = CGRectMake

How to determine and interpret the pixel format of a CGImage

半世苍凉 提交于 2019-12-06 00:09:36
问题 I'm loading this (very small) image using: UIImage* image = [UIImage named:@"someFile.png"]; The image is 4x1 and it contains a red, green, blue and white pixel from left to right, in that order. Next, I get the pixel data out of the underlying CGImage: NSData* data = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)); Now, for some reason, the pixel data is laid out differently depending on the iOS device. When I run the app in the simulator or on my iPhone 4, the pixel

Working with images (CGImage), exif data, and file icons

让人想犯罪 __ 提交于 2019-12-05 22:05:27
What I am trying to do (under 10.6).... I have an image (jpeg) that includes an icon in the image file (that is you see an icon based on the image in the file, as opposed to a generic jpeg icon in file open dialogs in a program). I wish to edit the exif metadata, save it back to the image in a new file. Ideally I would like to save this back to an exact copy of the file (i.e. preserving any custom embedded icons created etc.), however, in my hands the icon is lost. My code (some bits removed for ease of reading): // set up source ref I THINK THE PROBLEM IS HERE - NOT GRABBING THE INITIAL DATA

Drawing histogram of CGImage in Swift 3

拟墨画扇 提交于 2019-12-05 16:32:07
I have a problem with vImageHistogramCalculation_ARGB8888 method while trying to convert library from Swift 2 to Swift 3 version. The problem is that the method accepts "histogram" argument only as UnsafeMutablePointer<UnsafeMutablePointer<T>?> but Swift 3 construction let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>>(mutating: rgba) return unwrapped value, so I can't cast it to properly type. The compiler error is: : Cannot invoke initializer for type 'UnsafeMutablePointer?>' with an argument list of type '(mutating: [UnsafeMutablePointer])' Have you some ideas? I

Rotate and Crop UIImage

我的梦境 提交于 2019-12-05 11:24:28
Imagine I have an UIImage. I need to rotate and then crop it in the global coordinate system (not UIImage coordinate system). So the resulted image will be cropped and rotated. How can I do this? CGImageCreateWithImageInRect will crop image only in the image-relative coordinates. PS Answer in comments. You should use CIImage. Maybe this can help //init CIImage *image = [CIImage imageWithCGImage:CGImageRef]; //rotation CIImage *rotatedImage = [image imageByApplyingTransform:someTransform]; //crop CIImage *croppedImage = [rotatedImage imageByCroppingToRect:someRect]; For rotation, you need to

What does a correct call to CGImageCreate look like if the data provider for it uses an array created by the app?

我的梦境 提交于 2019-12-05 00:52:26
I'm trying to create a bitmap in memory as part of a pattern function that a drawLayer:inContext: method (this method is part of the CALayer delegate protocol) will call. The pattern function looks similar to this: static const size_t kComponentsPerPixel = 4; static const size_t kBitsPerComponent = sizeof(unsigned char) * 8; NSInteger layerHeight = 160; NSInteger layerWidth = 160; CGContextSaveGState(context); CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); size_t bufferLength = layerWidth * layerHeight * kComponentsPerPixel; unsigned char *buffer = malloc(bufferLength); // The real

iPhone - Get a pointer to the data behind CGDataProvider?

非 Y 不嫁゛ 提交于 2019-12-04 16:46:43
I'm trying to take a CGImage and copy its data into a buffer for later processing. The code below is what I have so far, but there's one thing I don't like about it - it's copying the image data twice. Once for CGDataProviderCopyData() and once for the :getBytes:length call on imgData. I haven't been able to find a way to copy the image data directly into my buffer and cut out the CGDataProviderCopyData() step, but there has to be a way...any pointers? (...pun ftw) NSData *imgData = (NSData *)(CGDataProviderCopyData(CGImageGetDataProvider(myCGImageRef))); CGImageRelease(myCGImageRef); // i've