cgimage

Swift: Add image to CAShapeLayer

折月煮酒 提交于 2019-12-01 11:59:26
I have a CAShapeLayer with a fill color, and want to add an icon in the center of this shape: var shape = CAShapeLayer() shape.fillColor = UIColor(white: 0.90, alpha: 1).CGColor var image = UIImage(named: "some_image") shape.contents = image?.CGImage This code does compile and does show the grey shape- but no image. :( I looked into these posts, but I can't cast the CGImage like they do. add UIImage in CALayer and Display an image or UIImage with a plain CALayer Is there another way? Or a workaround to the id cast? Full code: ViewController.swift import UIKit class ViewController:

CGImageRelease: [Not A Type release]: message sent to deallocated instance

血红的双手。 提交于 2019-12-01 11:18:48
问题 I'm getting this error "[Not A Type release]: message sent to deallocated instance" on the last line of code "CGImageRelease(imageToSave);". Please explain why and what I need to use to fix it. I'm using ARC, but I don't think that applies to CG objects. I've updated the code with the suggested answers after testing that they work. CGImageRef imageToSave; UIImage *uiImageToSave = [[UIImage alloc] init]; if (sender == nil) { imageToSave = [originalImage CGImage]; } else { uiImageToSave = [self

Swift: Add image to CAShapeLayer

余生颓废 提交于 2019-12-01 10:11:31
问题 I have a CAShapeLayer with a fill color, and want to add an icon in the center of this shape: var shape = CAShapeLayer() shape.fillColor = UIColor(white: 0.90, alpha: 1).CGColor var image = UIImage(named: "some_image") shape.contents = image?.CGImage This code does compile and does show the grey shape- but no image. :( I looked into these posts, but I can't cast the CGImage like they do. add UIImage in CALayer and Display an image or UIImage with a plain CALayer Is there another way? Or a

MKOverlay View is blurred

你离开我真会死。 提交于 2019-12-01 08:25:26
问题 I'm trying to add a png image as a custom map using MKOverlayView. I'm almost there - I am able to get the image lined up in the right place, and I know that the -drawMapRect: method in the subclass of MKOverlayView is being called periodically; I just can't seem to get the image to render properly. It's totally blurry, almost beyond recognition. I also know the image is large enough (it is 1936 × 2967). Here is my code for -drawMapRect: - (void)drawMapRect:(MKMapRect)mapRect zoomScale:

How to create CGImageRef from NSData string data (NOT UIImage)

☆樱花仙子☆ 提交于 2019-12-01 08:11:40
How does one create a new CGImageRef without a UIImage? I can't use image.CGImage I am receiving a base64 encoded image as a std::string from a server process. The first part of the code below simulates receiving the encoded string. - (UIImage *)testChangeImageToBase64String { UIImage *processedImage = [UIImage imageNamed:@"myFile.jpg"]; // UIImage to unsigned char * CGImageRef imageRef = processedImage.CGImage; NSData *data = (NSData *) CFBridgingRelease(CGDataProviderCopyData(CGImageGetDataProvider(imageRef))); // encode data to Base64 NSString NSString *base64EncodedDataString = [data

IOS: Using A Pattern Image As A Background -Memory Leak

眉间皱痕 提交于 2019-12-01 07:42:44
问题 OK. I'll be looking for the answer, and may find it myself. I have a nasty habit of answering my own questions. In any case, I have an app that is designed to be "skinned" fairly easily. As part of that, I have sequestered methods in a static class that is specific to variants. These static methods feed the main app images, colors and settings specific to the variant. The .h file is common to the main app, but the .m file is specific to the variant. I like to use the ability to send an image

How to create CGImageRef from NSData string data (NOT UIImage)

你离开我真会死。 提交于 2019-12-01 05:53:35
问题 How does one create a new CGImageRef without a UIImage? I can't use image.CGImage I am receiving a base64 encoded image as a std::string from a server process. The first part of the code below simulates receiving the encoded string. - (UIImage *)testChangeImageToBase64String { UIImage *processedImage = [UIImage imageNamed:@"myFile.jpg"]; // UIImage to unsigned char * CGImageRef imageRef = processedImage.CGImage; NSData *data = (NSData *) CFBridgingRelease(CGDataProviderCopyData

CGImage of UIImage return NULL

浪子不回头ぞ 提交于 2019-12-01 04:14:19
I created a function for splitting an image into multiple images, but when I take take the CGImage of the UIImage, the CGImage returns NULL NSArray* splitImage(UIImage* image,NSUInteger pieces) { NSLog(@"width: %f, %zu",image.size.width,CGImageGetWidth(image.CGImage)); NSLog(@"%@",image.CGImage); returns NULL NSMutableArray* tempArray = [[NSMutableArray alloc]initWithCapacity:pieces]; CGFloat piecesSize = image.size.height/pieces; for (NSUInteger i = 0; i < pieces; i++) { // take in account retina displays CGRect subFrame = CGRectMake(0,i * piecesSize * image.scale ,image.size.width * image

CGImage of UIImage return NULL

纵饮孤独 提交于 2019-12-01 02:05:12
问题 I created a function for splitting an image into multiple images, but when I take take the CGImage of the UIImage, the CGImage returns NULL NSArray* splitImage(UIImage* image,NSUInteger pieces) { NSLog(@"width: %f, %zu",image.size.width,CGImageGetWidth(image.CGImage)); NSLog(@"%@",image.CGImage); returns NULL NSMutableArray* tempArray = [[NSMutableArray alloc]initWithCapacity:pieces]; CGFloat piecesSize = image.size.height/pieces; for (NSUInteger i = 0; i < pieces; i++) { // take in account

Trim UIImage border

狂风中的少年 提交于 2019-11-30 21:30:10
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 colour in my images and they the colour value is indeed 255, but it doesn't seem to match what the above