core-graphics

Crop image in star shape iphone

走远了吗. 提交于 2019-12-22 10:19:21
问题 I have a image in rectangle shape but i want to crop this image in a star shape in my iphone application. so please can any one suggest how i do this? plz suggest. thanks 回答1: See the comment to a related question on how to mask an image. The magical part is CGContextClipToMask . 来源: https://stackoverflow.com/questions/5701152/crop-image-in-star-shape-iphone

Core Text in Cocoa app

感情迁移 提交于 2019-12-22 09:24:13
问题 I have the following sample code which works on iPhone. It draws the text "Hello World!" on the screen using Core Text. Dropping this code into a cocoa project in an NSView produces different results. The font size is scaled much bigger and the letters are drawn on top of each other. How do I have the text draw the same in the cocoa app? - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CFStringRef font_name =

In CoreGraphics drawing how can I keep the point of overlap from being darker than the rest of the line?

拟墨画扇 提交于 2019-12-22 09:02:05
问题 My app uses core graphics for custom finger paint drawing. I allow the user to change the alpha of the line and a new line is continuously drawn on touches moved. When I make the alpha lower than 1.0 the point of overlap is darker than the rest of the line. I know why this occurs but how can I stop this? 回答1: I suppose you want a single stroke not to darken itself, but still to darken previous strokes (that's how most painting apps work). For this to work, you need two views/buffers, one for

CAShapeLayer path disappears after animation - need it to stay in the same place

戏子无情 提交于 2019-12-22 08:11:26
问题 Thanks to some help on StackOverflow, I am currently animating a path in CAShapeLayer to make a triangle that points from a moving sprite to another moving point on the screen. Once the animation completes, the triangle disappears from the screen. I am using very short durations because this code is being fired every .1 of second for each of the sprites. The result is the red triangle tracks correctly, but it rapidly flashes or isn't there entirely. When I crank up the the duration, I can the

Create gradient image programmatically in iOS

橙三吉。 提交于 2019-12-22 07:58:36
问题 I'm trying to process some imagedata which comes directly from the device camera. In order to understand the CGImage structure, I'm using a buffer to create an image which doesn't work right for me (I know that I shouldn't use C code within Obj-C Code, it's just for understanding). The code is as follows: int *outBuf = malloc(sizeof(int) * width * height); for (int i = 0; i < width * height;i ++) { outBuf[i] = (((float)i) / ((float) width * height)) * 255.f; } CGColorSpaceRef colorSpace =

Scaling up iPhone “vector-based graphics” on affine transforms

女生的网名这么多〃 提交于 2019-12-22 07:00:13
问题 I made a "Circle" view with this drawRect - (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(ctx, color.CGColor); CGContextAddEllipseInRect(ctx, rect); CGContextFillPath(ctx); } When I try to scale the view up using CGAffineTransformMakeScale(2.0, 2.0) , the result is blurry and pixelated on the edges. However, the programming guide says that Quartz uses vector-based commands to draw views, and that they would continue to look good

iOS Core Graphics How to erase a drawing

十年热恋 提交于 2019-12-22 06:30:06
问题 I am following this tutorial for my doodle application. http://www.raywenderlich.com/18840/how-to-make-a-simple-drawing-app-with-uikit his erase function is using white color drawing. But I am using image background and when I erase, I really need to erase. I have tried CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); But it's not working. Here is my code: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { _mouseSwiped = NO; UITouch *touch = [touches

Porting creation of a PDF document from iOS to Mac OS X

人盡茶涼 提交于 2019-12-22 04:17:05
问题 I am porting my code from iPhone to Mac and I have no idea how I can do this in Mac. Here's my code that I am trying to convert and I know that there's no UIGraphic in Mac. Can someone point me to a guide or give me a quick hint? Thanks. NSString *newFilePath = @"path/to/your/newfile.pdf"; NSString *templatePath = @"path/to/your/template.pdf"; //create empty pdf file; UIGraphicsBeginPDFContextToFile(newFilePath, CGRectMake(0, 0, 792, 612), nil); CFURLRef url = CFURLCreateWithFileSystemPath

Drawing on the retina display using CoreGraphics - Image pixelated

不问归期 提交于 2019-12-22 04:10:10
问题 In my iOS application, I am trying to draw curves using CoreGraphics. The drawing itself works fine, but on the retina display the image gets drawn using the same resolution, and does not get pixel doubled. The result is a pixelated image. I am drawing using the following functions: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.canvasView]; UIGraphicsBeginImageContext(self.canvasView

Keeping the y-axis fixed at place?

萝らか妹 提交于 2019-12-22 01:07:18
问题 this is the code in the continuation of this question....Allow horizontal scrolling only in the core-plot barchart? -(BOOL)pointingDeviceDraggedAtPoint:(CGPoint)interactionPoint { if ( !self.allowsUserInteraction || !self.graph.plotArea ) { return NO; } CGPoint pointInPlotArea = [self.graph.plotArea convertPoint:interactionPoint toLayer:self.graph.plotArea]; if ( isDragging ) { pointInPlotArea.y = lastDragPoint.y;//-- Madhup Changed it for allwoing scrolling only in horizontal direction --//