cgimage

Convert image to grayscale

我的未来我决定 提交于 2019-12-17 03:25:13
问题 I am trying to convert an image into grayscale in the following way: #define bytesPerPixel 4 #define bitsPerComponent 8 -(unsigned char*) getBytesForImage: (UIImage*)pImage { CGImageRef image = [pImage CGImage]; NSUInteger width = CGImageGetWidth(image); NSUInteger height = CGImageGetHeight(image); NSUInteger bytesPerRow = bytesPerPixel * width; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *rawData = malloc(height * width * 4); CGContextRef context =

SWIFT 3 - CGImage copy always nil

不想你离开。 提交于 2019-12-14 02:28:23
问题 having this problem and trying to fix it for hours. func changeColorByTransparent(colorMasking : [CGFloat]) { UIGraphicsBeginImageContext(self.symbolImageView.frame.size) self.symbolImageView.layer.render(in: UIGraphicsGetCurrentContext()!) self.symbolImageView.image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() if let image = self.symbolImageView.image { print("image ok") if let cgimage = image.cgImage { print("cgimage ok") if let imageRef = cgimage.copy

Converting between UIImage (PNG) and RGB8

梦想与她 提交于 2019-12-13 12:43:49
问题 I am using https://github.com/PaulSolt/UIImage-Conversion However, it seems to have a problem on the alpha channel. Problem reconstituting UIImage from RGBA pixel byte data I have simplified the problem so I present it as a tidier question. I download Paul's project, run it. It displays an image in the centre of the screen -- everything so far is correct. But his demo is not testing for Alpha. So I attempt to composite my button image... ... on top. The result is: here is the code -- I have

How can I get the underlying pixel data from a UIImage or CGImage?

一个人想着一个人 提交于 2019-12-13 01:23:51
问题 I've tried numerous 'solutions' around the net, all of those I found have errors and thus don't work. I need to know the color of a pixel in a UIImage. How can i get this information? 回答1: Getting the raw data From Apple's Technical Q&A QA1509 it says this will get the raw image data in it's original format by getting it from the Data Provider. CFDataRef CopyImagePixels(CGImageRef inImage) { return CGDataProviderCopyData(CGImageGetDataProvider(inImage)); } Needed in a different format or

convert C# Xamarin.forms.image to CGImage

只谈情不闲聊 提交于 2019-12-12 16:26:51
问题 I am trying to convert a Xamarin.forms.image to a CoreGraphics.CGImage. void saveImg(Xamarin.Forms.Image image) { CoreGraphics.CGImage CGImage = (CoreGraphics.CGImage)image; } although this does not work... ERROR Message : "Cannot convert type 'Xamarin.Forms.Image' to 'CoreGraphics.CGImage' " What is the propper way to convert this image? 来源: https://stackoverflow.com/questions/46607138/convert-c-sharp-xamarin-forms-image-to-cgimage

iPhone: How to change the color of an image

谁都会走 提交于 2019-12-12 10:20:08
问题 I have a small image from a database and the image's average color need to be altered slightly. It's a CGImageRef and I thought of creating a CGContext , drawing the image to this context, then subsequently changing the bitmap data somehow and finally rendering it. But how can I alter the color information? Thanks for your help! 回答1: Check out this Apple Q&A on pixel data manipulation for details on how you might go about that. 回答2: Draw a color onto the object like this: // first draw image

Re: Get pixel data as array from UIImage/CGImage in swift

。_饼干妹妹 提交于 2019-12-12 03:36:17
问题 This code works for me (Swift 2 playground) in Gray scale, loading a colour .BMP image... Get pixel data as array from UIImage/CGImage in swift ... but if I change bytesPerPixel to 3 (or 4) and use let colorSpace = CGColorSpaceCreateDeviceRGB() ...the code still runs with no errors, but pixel values are all zeros. Any suggestions as to how to fix that? 回答1: You probably forgot the CGImageAlphaInfo parameter. For color images, if you assume bytesPerPixel to be 4, you need to set either RGBA

imageWithCGImage leaks according to instrument

为君一笑 提交于 2019-12-12 02:45:52
问题 Below is a screenshot from instrument app. Is there any explanation what is wrong with that line ? 回答1: ARC does not manage C-types, of which CGImage may be considered. You must release the ref manually when you are finished with CGImageRelease(image); found the answer hire 来源: https://stackoverflow.com/questions/23656934/imagewithcgimage-leaks-according-to-instrument

iOS layer mask from UIImage/CGImage?

蓝咒 提交于 2019-12-11 22:39:24
问题 I have the following image: On a UIImageView of the exact same frame size, I want to show everything but the red fill. let mask = CALayer() mask.contents = clippingImage.CGImage self.myImageView.layer.mask = mask I thought the black color would show through when applied as a mask, but when I set the mask the whole view is cleared. What's happening here? 回答1: When creating masks from images, you use the Alpha channel, rather than any RGB channel. Even if your mask is black, you need to set its

psd Image creation with layer properties using CGImageRef

戏子无情 提交于 2019-12-11 18:24:17
问题 Working in Mac OSX, Cocoa I have an psd image with layered property. I want to crop it to the crop rect and save this cropped image with the settings of original image. I am using CGImageRef for all the image related operations. I have enclosed the code i used to crop the image is given below. But it fails to create the layered image. NSImage *img = [[NSImage alloc]initWithContentsOfFile:imagePath]; NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:[img TIFFRepresentation]];