core-graphics

Load PDF from documents directory - iPhone

笑着哭i 提交于 2019-12-04 06:03:07
问题 Instead of loading a PDF from the resources folder I would like to load it from the documents directory. I have been trying to do this for days but the CGPDFDocumentRef keeps returning NULL. Here is my code: // Get Documents Directory NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [searchPaths objectAtIndex:0]; NSString *tempPath = [documentsDirectoryPath stringByAppendingPathComponent:[appDelegate

Converting a NSString to a cString for use with CGContextShowTextAtPoint

孤者浪人 提交于 2019-12-04 05:58:31
I am drawing a String using CGContextShowTextAtPoint. Thus I need to convert my NSString I want to draw into c Strings. Unfortunately special symbols like the euro currency symbol are not correctly shown. CGContextSelectFont(currentContext, "TrebuchetMS", 15, kCGEncodingMacRoman); CGContextShowTextAtPoint(currentContext, 0, 0, [myString cStringUsingEncoding:[NSString defaultCStringEncoding]], [myString length]); I tried it with the kCGEncodingFontSpecific encoding in the CGContextSelectFont function but that didn't work either. For performance reasons I need to use the CG Function, not the

Any possible way to call drawRect from a UIViewcontroller class?

偶尔善良 提交于 2019-12-04 05:25:15
问题 I have a UIViewController class called AppController.h , AppController.m . I have thousands of lines of code in there, and that is the only reason why I didn't test this before I asked it. Is there any possible way to use drawRect in a UIViewController ? that way I wouldn't have to make more delegates and methods and callbacks. I should have started off using drawRect to handle my drawing code, but I didn't, and there's severe lag with core graphics on the iPad. So, please let me know if

How can I fix a Core Image's CILanczosScaleTransform filter border artifact?

时光毁灭记忆、已成空白 提交于 2019-12-04 05:06:57
问题 I want to implement an image downscaling algorithm for iOS. After reading that Core Images's CILanczosScaleTransform was a great fit for it, I implemented it the following way: public func resizeImage(_ image: UIImage, targetWidth: CGFloat) -> UIImage? { assert(targetWidth > 0.0) let scale = Double(targetWidth) / Double(image.size.width) guard let ciImage = CIImage(image: image) else { fatalError("Couldn't create CIImage from image in input") } guard let filter = CIFilter(name:

Core Graphics & GIF Color Table

眉间皱痕 提交于 2019-12-04 04:41:52
I am trying to limit the number of colors of an animated GIF (created from an array of CGImageRef ). However, I am have difficulty actually setting the custom color table. Does anyone know how to do this with Core Graphics? I know of kCGImagePropertyGIFImageColorMap . Below is some test code (borrowing heavily from this github gist -- since it's the only instance of kCGImagePropertyGIFImageColorMap Google could find). NSString *path = [@"~/Desktop/test.png" stringByExpandingTildeInPath]; CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData

UIView drawRect: is it possible to stroke inside a path?

情到浓时终转凉″ 提交于 2019-12-04 04:15:37
With core graphics, is it possible to stroke the inside of a path? As opposed to the line weight being drawn half on the outside and half on the inside of a stroked path? The reason being it would be easier to control the visible thickness of the stroke if say part of a view is on the screen edge and part is not. The part on the screen edge gets cut off, while the view edge that is fully on screen looks thicker (as both sides if the stroke are visible). Clip to the path before you stroke it. This draws no stroke: - (void)drawRect:(CGRect)rect { CGContextRef context =

Draw Rectangle On UIImage with Core Graphics

心不动则不痛 提交于 2019-12-04 04:11:31
I'm trying to put a rectangle at the center of a UIImage using Core Graphics to look roughly like this: This is my code so far: func drawRectangleOnImage(image: UIImage) -> UIImage { let imageSize = image.size let scale: CGFloat = 0 UIGraphicsBeginImageContextWithOptions(imageSize, false, scale) let context = UIGraphicsGetCurrentContext() let rectangle = CGRect(x: 0, y: (imageSize.height/2) - 30, width: imageSize.width, height: 60) CGContextSetFillColorWithColor(context, UIColor.blackColor().CGColor) CGContextSetStrokeColorWithColor(context, UIColor.redColor().CGColor) CGContextSetLineWidth

What does CGColorGetComponents() return?

梦想与她 提交于 2019-12-04 03:11:30
CGFloat* colors = CGColorGetComponents(hsbaColor.CGColor); Does this return a float, or an array of floats? It looks like the asterisk is shorthand for creating an array. Is that correct? When I call this function on the CGColor property of an HSB UIColor object does it convert the values to RGB? hbw Yes, it returns an array of CGFloats . Specifically, it returns "an array of intensity values for the color components (including alpha) associated with the specified color." The color components returned depend on what color space the passed CGColorRef uses. More information can be found in the

Drawing dots and lines on to a UIView

陌路散爱 提交于 2019-12-04 02:47:26
I gave myself an exercise to learn Swift, based on an example I have found on the Apple Swift website : As you can see there's a river and a few dots in it right in the middle, forming a path. So I have started looking for a similar river image on the internet and I have created a Xcode playground. This is what I have now: So basically I have an UIView with a subview consisting in the river image I have found and a dot made with UIBezierPath . My first question is: is this the right way to drawn on to a UIView? I mean using a UIBezierPath . And my second question is: how do I draw the dot at a

Creating Gif Image Color Maps in iOS 11

你说的曾经没有我的故事 提交于 2019-12-04 02:10:01
I recently was having an issue when creating a Gif where if it got too big colors went missing. However thanks to help from SO someone was able to help me find a work around and create my own color map. Previous Question here... iOS Colors Incorrect When Saving Animated Gif This worked great up until iOS 11. I can't find anything in the docs that changed and would make this no longer work. What I have found is if I remove kCGImagePropertyGIFImageColorMap A gif is generated but it has the original issue where colors go missing if the gif gets to large like my previous question. This makes sense