cgcontext

CGImage recording distortion

自作多情 提交于 2020-06-27 12:51:08
问题 I've written a helper class to record a NSView and save it to a QuickTime file. The view is recorded fine to a QuickTime movie but the output is skewed for some reason. The core of my class is below, and the output is this: - (void) captureImage { [self getCGImageFromView]; pixelBuffer = [self getPixelBufferFromCGImage:viewCGImage size:CGRectMake(0, 0, mViewRect.size.width, mViewRect.size.height).size]; if(pixelBuffer) { if(![adapter appendPixelBuffer:pixelBuffer withPresentationTime

How to draw heart shape in UIView (iOS)?

萝らか妹 提交于 2020-05-06 06:36:26
问题 I want to create different shapes. Below image is the one of example. Will you suggest me how to different shapes? 回答1: Came across this when I was trying to draw a UIBezier-based heart myself, but was looking for one that looked a bit more like the one on Instagram posts. I ended up writing my own extension/class for it so I thought I'd share it on here in case it's of any use to anyone else who stumbles upon this in future. (This is all in Swift 3) First off, here's the UIBezier extension:

How to draw heart shape in UIView (iOS)?

我的梦境 提交于 2020-05-06 06:36:10
问题 I want to create different shapes. Below image is the one of example. Will you suggest me how to different shapes? 回答1: Came across this when I was trying to draw a UIBezier-based heart myself, but was looking for one that looked a bit more like the one on Instagram posts. I ended up writing my own extension/class for it so I thought I'd share it on here in case it's of any use to anyone else who stumbles upon this in future. (This is all in Swift 3) First off, here's the UIBezier extension:

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

Continuous drawing in CGContext with drawRect

放肆的年华 提交于 2020-02-07 06:56:20
问题 My question might be answered somewhere but I just couldn't find solution after a long research. I need to draw visually shapes (curves, lines, rectangles etc.) on iPhone one on top of the previous. I did that using CGContext to draw over an image and it's working fine. However in my app the drawing view resizes on device rotation and the lines become blurred because of the different image size. That's why I subclassed UIView and to call setNeedsDisplay from touchesMoved and touchesEnded . In

Erasing after drawing with CGContext

霸气de小男生 提交于 2020-01-22 05:56:08
问题 I'm trying to do a simple drawing app for the iPad where you can draw on a picture, and I'm using CGContext stuff to do it but the way I originally planned on handling erasing was to just draw over stuff with white...except I just realized today that it doesn't work when you're drawing onto another image because then when you "erase" you'll also "erase" the background image as well. Is there any way to support actual erasing? Thanks! 回答1: Display the user's drawing in a layer above the image.

how to make dashed line moveable

ⅰ亾dé卋堺 提交于 2020-01-13 05:10:50
问题 I used codes below to draw a dashed line // get the current CGContextRef for the view CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; // grab some useful view size numbers NSRect bounds = [self bounds]; float width = NSWidth( bounds ); float height = NSHeight( bounds ); float originX = NSMinX( bounds ); float originY = NSMinY( bounds ); float maxX = NSMaxX( bounds ); float maxY = NSMaxY( bounds ); float middleX = NSMidX( bounds ); float middleY =

EXC_BAD_ACCES drawing shadow

非 Y 不嫁゛ 提交于 2020-01-01 15:32:11
问题 I am trying to add a shadow to my UIView, but in my drawRect method I get an EXC_BAD_ACCESS. (I am using ARC) -(void) drawRect:(CGRect)rect { CGColorRef lightColor = [UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8].CGColor; CGColorRef shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4].CGColor; CGContextRef context = UIGraphicsGetCurrentContext(); // Draw shadow CGContextSaveGState(context); CGContextSetShadowWithColor(context, CGSizeMake

How to erase part of an image as the user touches it

江枫思渺然 提交于 2020-01-01 12:14:07
问题 My big picture goal is to have a grey field over an image, and then as the user rubs on that grey field, it reveals the image underneath. Basically like a lottery scratcher card. I've done a bunch of searching through the docs, as well as this site, but can't find the solution. The following is just a proof of concept to test "erasing" an image based on where the user touches, but it isn't working. :( I have a UIView that detects touches, then sends the coords of the move to the

Flatten UIViews Subviews to UIImage iPhone 3.0

扶醉桌前 提交于 2019-12-31 16:51:14
问题 I have a UIView that has several UIImageViews as subviews. Each of these subviews has had different affine transform applied. I would like to take what amounts to a screen capture of my UIView, capturing it as a UIImage, or some other image representation. The method I have tried already, rendering the layers to a CGContext with: [view.layer renderInContext:UIGraphicsGetCurrentContext()]; doesn't preserve the positioning or other affine transformations of my subviews. I would really