core-graphics

What are recommended Core Graphics techniques for drawing very custom UITableViewCells

柔情痞子 提交于 2019-12-23 04:03:52
问题 Hey guys. Curious on a couple key points about drawing something like this in core graphics. When should I use multiple layers? I know I can use a clipping path to do the rounding on the corners, and from what I understand it sounds like that's more efficient than putting a border radius on a CALayer. Is it possible to use the output from UIImageView in drawRect? I know you can't actually use the view, but I've seen in many places that UIImageView's are much more efficient for drawing images

Drawing CGImageRef in YUV

偶尔善良 提交于 2019-12-23 03:33:08
问题 I am using the code here to convert a CGImageRef into a CVPixelBufferRef on OS X . Convert UIImage to CVImageBufferRef However, I need the image to be drawn in YUV (kCVPixelFormatType_420YpCbCr8Planar) instead of RBG as it is now. Is there anyway to directly draw a CGImage in YUV colorspace? And if not, does anyone have an example for the best way to go about converting the CVPixedBufferRef from RBG into YUV ? I understand the formulas for the conversion but doing it on the CPU is painfully

NSString drawInRect set context

感情迁移 提交于 2019-12-23 01:16:26
问题 I draw some image in background. Sometimes my app crashes with strange error: function signature specialization < Arg[0] = Owned To Guaranteed> of MyApp. I checked all crashes, and I get all of them on methods that do not use context. One of them draw text. How can I specify context to draw text? UIGraphicsBeginImageContextWithOptions(size, false, 1.0) let ctx = UIGraphicsGetCurrentContext() // some code str.drawInRect(CGRectMake(floor(10 * scaleFactor), yOffset, size.width, floor(60 *

How do I get the RGB Value of a pixel using CGContext?

余生颓废 提交于 2019-12-23 00:26:33
问题 I'm trying to edit images by changing the pixels. I have the following code: let imageRect = CGRectMake(0, 0, self.image.image!.size.width, self.image.image!.size.height) UIGraphicsBeginImageContext(self.image.image!.size) let context = UIGraphicsGetCurrentContext() CGContextSaveGState(context) CGContextDrawImage(context, imageRect, self.image.image!.CGImage) for x in 0...Int(self.image.image!.size.width) { for y in 0...Int(self.image.image!.size.height) { var red = 0 if y % 2 == 0 { red =

Resize UIImage under memory constraints

南笙酒味 提交于 2019-12-22 23:20:16
问题 I have a massive UIImage downloaded from a web resource (>300MBs) which when I attempt to render is causing an app crash due to memory. I am trying to resize the image using the following code: + (UIImage *)imageWithImage:(UIImage *)image scaled:(float) scale { //UIGraphicsBeginImageContext(newSize); CGSize size = (CGSize){scale * image.size.width, scale * image.size.height}; UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); [image drawInRect:CGRectMake(0, 0, size.width, size.height)];

Swift - Clipping image with UIBezierPath

六月ゝ 毕业季﹏ 提交于 2019-12-22 17:52:03
问题 I would like to clip a bezier path from an image. For some reason, the image remains the unclipped. And how do I position the path so it would be properly cut? extension UIImage { func imageByApplyingMaskingBezierPath(_ path: UIBezierPath, _ pathFrame: CGFrame) -> UIImage { UIGraphicsBeginImageContext(self.size) let context = UIGraphicsGetCurrentContext()! context.saveGState() path.addClip() draw(in: CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)) let maskedImage =

How to Display International Accents with Quartz/Core Graphics on iPhone

六月ゝ 毕业季﹏ 提交于 2019-12-22 17:37:48
问题 I've localized an app for the iPhone. No surprise, the localization includes some accents: "Touch cards to select. Then touch 'Bid'." = "Touchez les cartes pour les sélectionner, puis touchez 'Miser'."; These work fine in high-level stuff, like when I put the text into a table, but when I try to write them to a UIView by hand, the accents get mangled: I'm using kCGEncodingMacRoman and UTF8, both of which should support accents, I think, but I'm clearly missing something: CGContextSelectFont

Fake long exposure on iOS

落花浮王杯 提交于 2019-12-22 14:58:10
问题 I have to implement long exposure photo capabilities to an app. Since i know that this is not really possible i have to fake it. It should work like "Slow Shutter" or "Magic Shutter". Sadly i got no clue how to achieve this. I know how to take images with the camera (through AVFoundation ) but i'm stuck at merging them to fake long shutter times. Possibly i need to manipulate and combine all the images with coregraphics but i'm not sure about this (even the how). Maybe there's a better

Fast way of obtaining thumbnail from ALAsset with filtered applied

六眼飞鱼酱① 提交于 2019-12-22 11:09:39
问题 A prompt and convenient way of gererating thumbnails from an ALAsset is described in the answer to question "Generating custom thumbnail from ALAssetRepresentation" — see a blog post of the author. The only issue I have with this method is that it completely ignores all the filters or red-eye removal effects applied to an image (say one taken with stock iOS 7 Photo app + any filter in 'square' mode). How should the code be adjusted to return 'filtered' thumbnails? P.S. I know I can get

How can I read-modify-write a PDF (CGPDFDocument) on iOS?

萝らか妹 提交于 2019-12-22 10:56:41
问题 I am trying to modify the PDF metadata (title, author, etc.) of an existing PDF on iOS. While it is easy to find sample code for PDF parsing and for PDF creation from scratch, there does not seem to be an easy way to dump an existing PDF into a new file - and modify it just slightly. More specifically, how do I get the info obtained when reading a PDF roughly like this: CGPDFDocumentRef myPDF = CGPDFDocumentCreateWithURL((CFURLRef)urlOfInputPDF); CGPDFDictionaryRef myPDFDict