core-graphics

Performance issues when cropping UIImage (CoreGraphics, iOS)

ぐ巨炮叔叔 提交于 2019-12-10 21:14:27
问题 The basic idea of what we are trying to do is that we have a large UIImage, and we want to slice it into several pieces. The user of the function can pass in a number of rows and number of columns, and the image will be cropped accordingly (ie. 3 rows and 3 columns slices the image into 9 pieces). The problem is, we're having performance issues when trying to accomplish this with CoreGraphics. The largest grid we require is 5x5, and it takes several seconds for the operation to complete

UIImageView subclass needs to handle resize

佐手、 提交于 2019-12-10 20:20:22
问题 I am creating a UIImageView subclass to display an audio waveform. The approach is to load the file, do math, save a PNG file and then self.image = thePNG . The nice part about this is that on a resize or repaint the UIImageView will stretch the PNG and stretch quickly. Now if the image is expanded too much then I need to recalculate the waveform to avoid visible pixelation. Since we know that UIImageView does not call drawRect, is there a method that is called during resize so that I can

Joined lines at certain angles have pointed vertexes instead of rounded

烈酒焚心 提交于 2019-12-10 19:19:18
问题 My app allows you to draw using a variety of tools. One of them lets you make an angle: you tap three times, then an angle is drawn for you. Unfortunately, it gets really pointy but then rounded again at certain angles for some reason. I'm using CGContextSetLineCap(context, kCGLineCapRound); Here is a picture to exemplify what I'm talking about: Does anyone know what causes this or how to fix it so it is round all the time?? For the most part, all I do is: CGContextMoveToPoint(context, first

Call CGPatternCreate in Swift

余生颓废 提交于 2019-12-10 18:08:34
问题 I'm wondering how to convert the following objective-c method to Swift function? CGPatternRef pattern = CGPatternCreate(NULL, rect, CGAffineTransformIdentity, 24, 24, kCGPatternTilingConstantSpacing, true, &callbacks); My code: let callbacks : CGPatternCallbacks = CGPatternCallbacks(version: 0) let pattern : CGPatternRef = CGPatternCreate(nil, rect, CGAffineTransformIdentity, 24, 24, kCGPatternTilingConstantSpacing, true, callbacks) But I got an error message: 'CGPatternCallbacks' is not

CGAffineTranformRotate atan2 inaccuration

為{幸葍}努か 提交于 2019-12-10 17:12:10
问题 I'm making transition of my view and always happens something weird, I mean I calculate angle using this code: angle = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x); And the view rotates but not properly. I mean it rotates in proper direction but the angle is always inaccurate about +/- 0.05 radians. And when I tap again, view rotates into proper position . Any adivices? It's important to me to

Using Multiple CGAffineTransforms On Text Matrix

我的未来我决定 提交于 2019-12-10 17:11:26
问题 I am displaying text using Quartz. Here is my code: CGContextRef myContext = UIGraphicsGetCurrentContext(); CGContextSelectFont(myContext, "Helvetica", 12, kCGEncodingMacRoman); CGContextSetCharacterSpacing(myContext, 8); CGContextSetTextDrawingMode(myContext, kCGTextFillStroke); CGContextSetRGBFillColor(myContext, 0, 0, 0, 1); CGContextSetRGBStrokeColor(myContext, 0, 0, 0, 1); CGContextSetTextMatrix(myContext,CGAffineTransformMake(1, 0, 0, -1, 0, 0)); CGContextShowTextAtPoint(myContext,

iPhone SDK Invert the Colors of a UIImage

喜欢而已 提交于 2019-12-10 16:45:11
问题 I've got an iPhone app that allows a person to draw something on the screen with their finger. They draw with a white line on a black background. However, when I upload this image to the web server, the line itself is white. I have been trying to work through the core graphics libraries in search of a way to invert the colour of the drawn image. There is no background set so it should be transparent. Doing an image invert should swap the white to black. Does anyone know if this is possible

Accessing CGRect values directly vs normalizing them in Swift - Objective-C rules still valid?

ⅰ亾dé卋堺 提交于 2019-12-10 16:43:06
问题 This question is inspired by Andrew Carter's comment on a previous question about the new CGSize initializer in Swift. The Apple Docs for CGGeometry say: ... your applications should avoid directly reading and writing the data stored in the CGRect data structure. Instead, use the functions described here to manipulate rectangles and to retrieve their characteristics. Is Apple's recommendation to not directly access the data in a CGRect still valid with Swift? Why should CGRectGetMidX ,

Issue with erase or transparent stroke using CoreGraphics framework

孤街醉人 提交于 2019-12-10 16:14:41
问题 In one of my apps, am trying to erase/transparent stroke a part of UIImage which am drawing using CoreGraphics framework ( CGContextRef etc..). Well in the process I am able to clear the drawing in one shot by calling "removeAllObjects" message, but I was not able to figure out, how to erase a part of the drawing image. Gosh!! I sat the whole day but still no results, now its killing me. Please guys help me out from here. In short, my requirement is something like an eraser which can erase a