core-graphics

Rotate image using CGContextDrawImage

倾然丶 夕夏残阳落幕 提交于 2020-03-09 13:51:10
问题 How can I rotate an image drawn by CGContextDrawImage() at its center? In drawRect: CGContextSaveGState(c); rect = CGRectOffset(rect, -rect.size.width / 2, -rect.size.height / 2); CGContextRotateCTM(c, angle); CGContextDrawImage(c, rect, doodad.CGImage); CGContextRotateCTM(c, -angle); CGContextTranslateCTM(c, pt.x, pt.y); prevRect = rect; CGContextRestoreGState(c); I draw the image at the origin, and rotate it at its center, then translate to where it should be drawn. Not working. 回答1: The

draw pie chart using iOS quartz 2D

狂风中的少年 提交于 2020-02-24 11:23:25
问题 I am looking for a tutorial where I can draw pie chart programmatically using Core Graphics or Quartz 2D in iOS. I want to understand how can we draw the PIE Chart which is gradient and having multi-color filled slices in it. Note: Not looking for Coreplot framework. Please share me some links regarding the same. 回答1: I have used "XYPieChart" library in my so many apps and it's very easy to modify. Available on github. Link is given below: https://github.com/xyfeng/XYPieChart Still needs any

How do I process a mouse click using Quartz events?

偶尔善良 提交于 2020-02-23 04:06:19
问题 I have a CGEventTap and I would like to observe and process all system mouse click events. Detecting a mouse click event is easy, but I don’t want some of the clicks to get processed by the rest of the system. And I can’t figure out how. The system only sends low-level events like mouseUp , mouseDown , mouseDragged and so on. When I receive a mouseDown event, I don’t know if it’s a part of a mouse click yet, could be a drag event. I have to wait for the following event – if it’s a mouseUp , I

Core Graphics coordinate system

霸气de小男生 提交于 2020-02-21 10:22:06
问题 When overriding drawRect I've found that the coordinates there use 0,0 as the upper left. But the Apple UIView Programming Guide says this: Some iOS technologies define default coordinate systems whose origin point and orientation differ from those used by UIKit. For example, Core Graphics and OpenGL ES use a coordinate system whose origin lies in the lower-left corner of the view or window and whose y-axis points upward relative to the screen. I'm confused; are they talking about something

convert an opencv affine matrix to CGAffineTransform

余生颓废 提交于 2020-02-21 05:57:14
问题 I'd like to take an affine matrix that I have from OpenCV: Mat T = getAffineTransform(src_pt, dst_pt); and then convert it into a CGAffineTransform for use in Core Graphics/Objective-C/iOS. (CGAffineTransform docs) I've tried: CGAffineTransform t = CGAffineTransformIdentity; t.a = T.at<float>(0,0); t.b = T.at<float>(0,1); t.c = T.at<float>(1,0); t.d = T.at<float>(1,1); t.tx = T.at<float>(0,2); t.ty = T.at<float>(1,2); This works fine for x and y translations, but NOT if there is any rotation

CGPDF<…> - where are the setters?

给你一囗甜甜゛ 提交于 2020-02-04 14:34:29
问题 Is there any way to create PDF objects (e.g. a PDF-dictionary with parameters that are needed by a custom PDF producer/consumer/viewer) with CGPDF<...> or do I have to write my own parser and create new trailers, xref etc. in order to add new objects to the PDF? As I understand it, CG translates all drawing calls of its graphics context into the correct PDF counterparts when creating a PDF - but I have custom data/objects (e.g. for annotations, threads etc.) that should be stored in the PDF

Multiple Clipped Rects to Create Collage in Core Graphics

一个人想着一个人 提交于 2020-01-30 18:13:03
问题 I am creating a collage combined with elements from other images. Here is some ASCII art to explain what I am doing: Given images A, B and C, AAA, BBB, CCC AAA, BBB, CCC AAA, BBB, CCC I take part of A, part of B and part of C as columns: Axx, xBx, xxC Axx, xBx, xxC Axx, xBx, xxC ...and combine them in one image like this: ABC ABC ABC where the first 1/3rd of the image is a colum of A's pic, the middle is a column of B's pic and the last is a column of C's pic. I have some code written but it

Multiple Clipped Rects to Create Collage in Core Graphics

谁说我不能喝 提交于 2020-01-30 18:11:39
问题 I am creating a collage combined with elements from other images. Here is some ASCII art to explain what I am doing: Given images A, B and C, AAA, BBB, CCC AAA, BBB, CCC AAA, BBB, CCC I take part of A, part of B and part of C as columns: Axx, xBx, xxC Axx, xBx, xxC Axx, xBx, xxC ...and combine them in one image like this: ABC ABC ABC where the first 1/3rd of the image is a colum of A's pic, the middle is a column of B's pic and the last is a column of C's pic. I have some code written but it

Lines drawn with core graphics that are set to the same width sometimes vary in size when drawn

旧城冷巷雨未停 提交于 2020-01-25 10:23:19
问题 Here is a picture of two lines drawn in a UITableViewCell with the same function, and same width, and color As you can see the bottom line is a lot thicker than the other line. The code I am using for drawing: [CSDrawing drawLineWithColor:[UIColor blackColor] width:1.0 yPosition:1.0 rect:rect]; [CSDrawing drawLineWithColor:[UIColor blackColor] width:1.0 yPosition:CGRectGetMaxY(rect) - 3.0 rect:rect]; // draw a line on top and bottom +(void)drawLineWithColor:(UIColor *)color width:(CGFloat

Drawing a gradient color in an arc with a rounded edge

梦想与她 提交于 2020-01-23 17:36:08
问题 I want to replicate this in Swift.. reading further: How to draw a linear gradient arc with Qt QPainter? I've figured out how to draw a gradient inside of a rectangular view: override func drawRect(rect: CGRect) { let currentContext = UIGraphicsGetCurrentContext() CGContextSaveGState(currentContext) let colorSpace = CGColorSpaceCreateDeviceRGB() let startColor = MyDisplay.displayColor(myMetric.currentValue) let startColorComponents = CGColorGetComponents(startColor.CGColor) let endColor =