core-graphics

Resetting the origin of a transformed UIView descends into craziness

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 21:58:40
I rotate/scale a UIVIew using [UIView transform:] and this works well. However, as soon as I change the view's frame origin the contents of the view begins to scale 'weirdly' even though I am not performing any further CGAffineTransforms. Why does this occur? How can I prevent it? Update 1: The docs suggest that the frame is invalid after a transform. Can I move the view via it's 'center' property instead? Update 2: Setting the views center did allow me to translate the view successfully after a transform had been applied. Can I move the view via it's 'center' property instead? The

draw a line in UIImageView problem

微笑、不失礼 提交于 2019-12-03 21:45:06
In my application i can draw a line in a UIImageView by the code below,and i want redraw the line even longer when i call the function,however,the output come out is not as expected,it will just draw a new line and remove the old one,the length is remain the same jus the y position different,i dont know which line of my code is wrong or i havent understand the CGContext class in correct way,please help i have scratch my head all the days and cannot find out the problem - (void) drawLine { lastPoint = currentPoint; lastPoint.y -= 40; //drawImage is a UIImageView declared at header

Clipping a CGGradient to a CGPath

和自甴很熟 提交于 2019-12-03 21:25:54
I've been banging my head against the wall for a long while trying to figure out why this is not working. Basically, I am trying to plot a graph (chart) with CGPath and then use that to clip a gradient. The end effect should be like the Stocks app which comes with the iPhone. The gradient and the path draw fine separately as two layered (unclipped) elements. But if I comment out the CGContextDrawPath, neither the line nor the gradient draw to the screen. Here's my drawRect code: CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor whiteColor] set]; CGContextSetLineWidth(context, 2

Cropping a UIImage according to the viewport inside a UIScrollView

≡放荡痞女 提交于 2019-12-03 21:14:37
I have a UIImageView (initialized with Aspect Fill) inside a UIScrollView. The user shall use that to resize and position a UIImage to his like, press a button and then exactly what he sees on screen would be sent to a server, only in the original image coordinates. In other words, the resulting image would be bigger than the image on screen. Here's the essential part of my code so far: // select the original CGFloat imageRatio = self.imageView.image.size.width / self.imageView.image.size.height; CGFloat viewRatio = self.imageView.frame.size.width / self.imageView.frame.size.height; CGFloat

Writing with digital pen on ipad/iphone by keeping hand on screen

∥☆過路亽.° 提交于 2019-12-03 21:10:19
I am working on a drawing app, with pen touch, on iphone and ipad. Till now , I have implemented the basic drawing and tested with digital pen and it work fine, but I have one issue, while drawing on iphone/ipad, if my fingers touch the screen before I draw with pen , the pen wont work, So what I want to achieve is that, I want to able to write with pen, even if my fingers are touching the ipad screen. Regards Ranjit There is no way to differentiate between a finger and a stylus, as a stylus is supposed to emulate a touch from a finger. You will either have to make it so that all touches draw

Drawing around CGContextRef to remove pixelation

萝らか妹 提交于 2019-12-03 20:48:23
Currently, I am having a graphical issue with drawing small dots. I notice that in most professional Calendar applications, the events calendar indentifier is a small dot whose color is the events calendar color. I am current at the point of my application where I need to draw a BETTER dot. Heres a photo of what I mean. It may not be noticeable here but the colored dot is pretty pixelated when its on my phone. I would like to remove the pixelation. I went through a tutorial from Ray Wenderlich's website: Ray Wenderlich Core Graphics . Here is what I got out of it for drawing the dot:

Optimize Core Graphics animated drawing (iPhone)

落爺英雄遲暮 提交于 2019-12-03 20:17:10
I have a loop that fires a function 30 times per second. The function changes the position of a couple of points that I use to animate. I draw lines through all the points, meaning that the lines will change 30 times per second. I draw these lines to a CGLayer, which then is drawn to a UIView in the drawRect: method. I do this because I understand that performance is improved when drawing offscreen. However, it seems that the CGLayer saves all actual lines instead of drawn pixels, since even if I clear it, the program runs slower and slower over time when more lines are drawn. I'm asking for

Drawing in a background thread on iOS

社会主义新天地 提交于 2019-12-03 19:34:44
问题 I have a view with some very complex drawing logic (it's a map view that draws from GIS data). Doing this drawing on the main thread locks up the UI and makes the app unresponsive. I want to move away the drawing to a background thread with for example an NSOperation. What is the best way to structure this? I am currently drawing to an off memory CGContext and then convert that to a CGImageRef which I send to the view to blit on the main thread. Unfortunately this uses up a lot of memory and

How to remove the transparent area of an UIImageView after masking?

二次信任 提交于 2019-12-03 19:20:20
In one of my iOS applications, I am trying to cut a portion of an image using CGImageMask . I have succeeded in masking the image with the following code: - (UIImage *)maskImage:(UIImage *)referenceImage withMask:(UIImage *)maskImage { CGImageRef maskRef = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask([referenceImage CGImage], mask); return

reading value in CFDictionary with swift

江枫思渺然 提交于 2019-12-03 19:13:17
问题 I'm just starting with swift and cocoa. I'm trying to create a basic app that does image manipulation. I've allready got all information of the image with this: let imageRef:CGImageSourceRef = CGImageSourceCreateWithURL(url, nil).takeUnretainedValue() let imageDict:CFDictionaryRef = CGImageSourceCopyPropertiesAtIndex(imageRef, 0, nil).takeUnretainedValue() the dictionary contains following information: { ColorModel = Gray; DPIHeight = 300; DPIWidth = 300; Depth = 1; Orientation = 1;