CGImage represents a drawable image object in Core Graphics (the low-level procedural drawing API for iOS and Mac OS X).
Questions tagged [cgimage]
563 questions
17
votes
1 answer
Why is cgImage?.cropping rotating the image?
I have written a UICropperViewController and it is working perfectly for images in landscape mode. Images in portrait mode have a huge problem. The following picture shows a simple picture with a yellow crop frame:
The cropping result is:
Now when…

Mulgard
- 9,877
- 34
- 129
- 232
16
votes
4 answers
How to crop a UIImage without losing it's scale property?
Goal: Crop a UIImage (that starts with a scale property of 2.0)
I perform the following code:
let croppedCGImage = originalUIImage.cgImage!.cropping(to: cropRect)
let croppedUIImage = UIImage(cgImage: croppedCGImage!)
This code works, however the…

bearMountain
- 3,950
- 1
- 36
- 44
16
votes
2 answers
Swift 3.0: How to call CGImageCreateWithImageInRect()?
I need to implement this Objective-C code in Swift 3.0 (I'm using Xcode 8 Beta 3):
// Note: this code comes from an Obj-C category on UIImage
CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, cropRect);
UIImage *image = [UIImage…

RobertJoseph
- 7,968
- 12
- 68
- 113
16
votes
6 answers
Turning an NSImage* into a CGImageRef?
Is there an easy way to do this that works in 10.5?
In 10.6 I can use nsImage CGImageForProposedRect: NULL context: NULL hints: NULL
If I'm not using 1b black and white images (Like Group 4 TIFF), I can use bitmaps, but cgbitmaps seem to not like…

Brian Postow
- 11,709
- 17
- 81
- 125
16
votes
1 answer
Why is my image's Bytes per Row more than its Bytes per Pixel times its Width?
I'm converting images to a MOV file, and had an interesting thing happen to me. I logged my bits per color component, bits per pixel, and bytes per row. Here's my code:
NSLog(@"Image width: %d, Height: %d", CGImageGetWidth(image),…

Herm
- 411
- 5
- 14
15
votes
3 answers
Core Graphics CGImage mask not affecting
What I'm essentially trying to do is have a text label 'cut' a text-shaped hole through the view. I've tried using self.mask = uiLabel but those refused to position the text correctly so I'm approaching this through Core Graphics.
Here's the code…

Downgoat
- 13,771
- 5
- 46
- 69
15
votes
4 answers
Square thumbnail from UIImagePickerViewController image
In my app the user selects an image or take a picture using UIImagePickerViewController. Once the image was selected I want to display its thumbnail on a square UIImageView (90x90).
I'm using Apple's code to create a thumbnail. The problem is the…

douglasd3
- 761
- 2
- 10
- 27
15
votes
6 answers
Rotating a CGImage
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…

null0pointer
- 1,533
- 3
- 15
- 29
13
votes
1 answer
What does a correct call to CGImageCreate look like if the data provider for it uses an array created by the app?
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…

Jim
- 1,014
- 1
- 11
- 22
13
votes
4 answers
UIImage created from CGImageRef fails with UIImagePNGRepresentation
I'm using the following code to crop and create a new UIImage out of a bigger one. I've isolated the issue to be with the function CGImageCreateWithImageInRect() which seem to not set some CGImage property the way I want. :-) The problem is that a…

Ari J.R.
- 461
- 3
- 7
13
votes
2 answers
Generating custom thumbnail from ALAssetRepresentation
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…

Scakko
- 548
- 6
- 17
12
votes
3 answers
How to create empty/blank UIImage or CGImage and manipulate pixels on it (Xcode)?
I have following problem and only could solve it partially yet. I am working with XCode 3.2.5, developing for iOS 4+.
I simply try to create an Image of pre-defined size, manipulate pixels on it and then show the Image in an UIImageView. My view…

EliteTUM
- 705
- 2
- 8
- 21
12
votes
2 answers
Drawing image in Swift takes forever
In my app I'm creating an image mapping floats to a pixel value and use it as an overlay on Google Maps, but it takes forever to do, the same thing in Android is almost instant. My code looks like this:
private func imageFromPixels(pixels:…

Recusiwe
- 1,594
- 4
- 31
- 54
12
votes
3 answers
Should I use UIImage or CGImage in a Swift iOS App?
All the code I can find revolves around loading images directly into visual controls.
However, I have my own cache system (converting a project from another language) and so I as efficient as possible want the following:
Load jpg/png images -…

Tom
- 3,587
- 9
- 69
- 124
12
votes
3 answers
Image decompression in iOS 7
The problem of image decompression has been much discussed in Stack Overflow but up to this question there were 0 mentions of kCGImageSourceShouldCacheImmediately, an option introduced in iOS 7 that, in theory, takes care of this problem. From the…

hpique
- 119,096
- 131
- 338
- 476