cgimage

Swift: Cropping a Screenshot without TabBar and NavigationBar

烂漫一生 提交于 2019-11-30 20:43:43
I have a screenshot of the entire screen, screenshot , generated using the following: let layer = UIApplication.sharedApplication().keyWindow!.layer let scale = UIScreen.mainScreen().scale UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale); layer.renderInContext(UIGraphicsGetCurrentContext()) let screenshot = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() I'd like to crop it so that the tab bar is not included, and I tried using the following code: let crop = CGRectMake(0, 0, //"start" at the upper-left corner self.view.bounds.width, //include half

Trim UIImage border

梦想的初衷 提交于 2019-11-30 17:40:19
问题 Here's an example of an image I would like to trim. I want to get rid of the borders around the image (in this case the top and bottom black bars). I found a library on Github: CKImageAdditions, however it doesn't seem to work. When I pass in a UIColor (with RGB colours) it just returns the same image. I can find a lot of examples and category classes that would trim a UIImage with any transparent pixels as the border, but in this case I need to trim the black colour. I have sampled the

Getting a CGImage from CIImage

房东的猫 提交于 2019-11-30 17:17:27
I have a UIImage which is loaded from a CIImage with: tempImage = [UIImage imageWithCIImage:ciImage]; The problem is I need to crop tempImage to a specific CGRect and the only way I know how to do this is by using CGImage . The problem is that in the iOS 6.0 documentation I found this: CGImage If the UIImage object was initialized using a CIImage object, the value of the property is NULL. A. How to convert from CIImage to CGImage? I'm using this code but I have a memory leak (and can't understand where): +(UIImage*)UIImageFromCIImage:(CIImage*)ciImage { CGSize size = ciImage.extent.size;

UIImage created from CGImageRef fails with UIImagePNGRepresentation

假如想象 提交于 2019-11-30 12:10:35
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 call to function UIImagePNGRepresentation() fails returning a nil. CGImageRef origRef = [stillView.image CGImage]; CGImageRef cgCrop = CGImageCreateWithImageInRect( origRef, theRect); UIImage *imgCrop = [UIImage imageWithCGImage:cgCrop]; ... NSData *data = UIImagePNGRepresentation ( imgCrop); -- libpng error: No IDATs written into file Any idea what

How do I capture a zoomed UIImageView inside of a Scrollview to crop?

人盡茶涼 提交于 2019-11-30 10:39:58
Problem: Cropping with the image zoomed out is fine. Cropping with the image zoomed in is showing the image above what is should be. The yOffset I have in there is because the crop square I want starts below where the scrollview does. Code: CGRect rect; float yOffset = 84; rect.origin.x = floorf([scrollView contentOffset].x * zoomScale); rect.origin.y = floorf(([scrollView contentOffset].y + yOffset) * zoomScale); rect.size.width = floorf([scrollView bounds].size.width * zoomScale); rect.size.height = floorf((320 * zoomScale)); if (rect.size.width > 320) { rect.size.width = 320; } if (rect

Crop UIImage to alpha

此生再无相见时 提交于 2019-11-30 09:07:25
I have a rather large, almost full screen image that I'm going to be displaying on an iPad. The image is about 80% transparent. I need to, on the client, determine the bounding box of the opaque pixels, and then crop to that bounding box. Scanning other questions here on StackOverflow and reading some of the CoreGraphics docs, I think I could accomplish this by: CGBitmapContextCreate(...) // Use this to render the image to a byte array .. - iterate through this byte array to find the bounding box .. CGImageCreateWithImageInRect(image, boundingRect); That just seems very inefficient and clunky.

UIImage created from CGImageRef fails with UIImagePNGRepresentation

白昼怎懂夜的黑 提交于 2019-11-29 17:28:03
问题 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 call to function UIImagePNGRepresentation() fails returning a nil. CGImageRef origRef = [stillView.image CGImage]; CGImageRef cgCrop = CGImageCreateWithImageInRect( origRef, theRect); UIImage *imgCrop = [UIImage imageWithCGImage:cgCrop]; ... NSData

How do I capture a zoomed UIImageView inside of a Scrollview to crop?

断了今生、忘了曾经 提交于 2019-11-29 15:51:19
问题 Problem: Cropping with the image zoomed out is fine. Cropping with the image zoomed in is showing the image above what is should be. The yOffset I have in there is because the crop square I want starts below where the scrollview does. Code: CGRect rect; float yOffset = 84; rect.origin.x = floorf([scrollView contentOffset].x * zoomScale); rect.origin.y = floorf(([scrollView contentOffset].y + yOffset) * zoomScale); rect.size.width = floorf([scrollView bounds].size.width * zoomScale); rect.size

Crop UIImage to alpha

谁说胖子不能爱 提交于 2019-11-29 13:54:32
问题 I have a rather large, almost full screen image that I'm going to be displaying on an iPad. The image is about 80% transparent. I need to, on the client, determine the bounding box of the opaque pixels, and then crop to that bounding box. Scanning other questions here on StackOverflow and reading some of the CoreGraphics docs, I think I could accomplish this by: CGBitmapContextCreate(...) // Use this to render the image to a byte array .. - iterate through this byte array to find the bounding

How can I get screenshot from all displays on MAC?

南笙酒味 提交于 2019-11-29 13:08:38
I try to get the screenshot from all monitors connected with my MAC to one picture. I know, how I can do this if every monitor's screenshot will saved to different pictures, but it is not what I want. I found function CGGetDisplaysWithRect , but my solution don't work, because output picture is empty. I expect, that problem with function CGDisplayCreateImageForRect (*displays, rect), because first parameter must be CGDirectDisplayID type, but not CGDirectDisplayID*. But I can't find function, which can create one picture with some CGDirectDisplayID objects. Help me please!!! #include <stdio.h>