drawrect

How to draw a rectangle?

非 Y 不嫁゛ 提交于 2019-12-17 22:41:34
问题 I want to draw a filled rectangle in my viewContoller's view. I wrote the code below in viewDidLoad. But there is no change. What is wrong? CGRect rectangle = CGRectMake(0, 100, 320, 100); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0); CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); CGContextFillRect(context, rectangle); 回答1: You can't do it in a viewController. You need to extend your View and add the code under "drawRect

Having UIView drawRect occur in a background thread

为君一笑 提交于 2019-12-17 19:51:39
问题 I would like to have a UIView subclass that implements a method similar to setNeedsDisplay , except that redrawing (i.e., that would usually be called via drawRect: ) will occur in a background thread sometime soonish, rather than at the end of the current update cycle. It might be called setNeedsAsynchronousDisplay . Or the existing setNeedsDisplay could get hijacked and not cause redraw at the end of the cycle, or whatever, as long as it lets the redraw not happen on the main thread

Mysterious “progressive slowing” problem in run loop / drawRect

跟風遠走 提交于 2019-12-17 18:43:40
问题 Here's a real mystery. Imagine you are doing the conventional process of drawing a complex image offscreen (CGLayer), and you are updating the image on to the screen intermittently as you draw. As you know the way to do this is: run the large drawing process in the background, and call to the foreground for setNeedsDisplays as desired, causing the image to be updated. This is trivial and achieved with two lines of code. However, when you do this, there is a mysterious problem: the time taken

Java how to paint rectangles on mouseclick

心不动则不痛 提交于 2019-12-17 10:04:20
问题 As the title says, I'm having a hard time trying to draw some rectangles (filled) in JApplet. The exact goal is to have a 50x50 table and when you click on a targeted cell, to make it filled (possibly done by drawing a filled rectangle). I have done the maths about the coordinates of the starting point, but for some reason I can't draw the new rectangle in the MouseClicked method. Any suggestions? public class Main extends JApplet { public static final int DIMX = 800; public static final int

Animate drawing of a circle

帅比萌擦擦* 提交于 2019-12-17 03:20:56
问题 I'm looking for a way to animate the drawing of a circle. I have been able to create the circle, but it draws it all together. Here is my CircleView class: import UIKit class CircleView: UIView { override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = UIColor.clearColor() } required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func drawRect(rect: CGRect) { // Get the Graphics Context var context =

Custom Drawing of Alpha Images

泪湿孤枕 提交于 2019-12-13 15:23:58
问题 I am trying to do custom drawing of an image(with alpha) and eventually going to apply different color tints to it. Right now I am just trying to draw it correctly. This might be simple problem but the result is the ALPHA on my image is black. Image is .png created from photoshop with correct alpha. - (void) drawRect:(CGRect)area { [imgView.image drawInRect: area blendMode:blendMode alpha:alpha]; // draw image } blendMode is normal and alpha is 1.0. The image is good except alpha being black.

Any possible way for CoreGraphics to not lag when drawrect is being called from touches moved?

人盡茶涼 提交于 2019-12-13 07:06:37
问题 I am calling setNeedsDisplay from touches moved (and have also tried not calling from touches moved, but instead from a 0.05 timer) and the drawrect method is always laggy. Is their anyway to change this? I am doing a lot of drawing in drawrect but I have no idea for a solution to fix the lag. Even when the timer was called at a 1.0 interval than it still lagged when the timer called the selector. Also, I have no leaks (I checked using Xcode analyze feature ). Please help!! EDIT: I am calling

How to create Clickable Rectangles?

江枫思渺然 提交于 2019-12-13 04:42:37
问题 Im drawing an indoor map using DrawRect method. I want to identify each rectangle by the user's OnTouch Event.How can i make it happen? I want to know if i can use the drawn Rectangles as independent objects Where i can identify them uniquely. UPDATED I tried this. But it gives me errors.How can i create a new intent withing the for loop?? :( ArrayList<Rect> rectangles = new ArrayList<Rect>(); {rectangles.add(new Rect(232,78,419,238)); rectangles.add(new Rect(285,27,524,239)); rectangles.add

drawInRect of UIImage is Not working

血红的双手。 提交于 2019-12-13 04:26:51
问题 I am Hardly Trying to learn New things with CoreGraphics. I have a the below code and the image is not set using drawInRect function. - (void)viewDidLoad { [super viewDidLoad]; imgView=[[UIImageView alloc]init]; [self drawRect:CGRectMake(10, 10, 20, 20)]; } - (void)drawRect:(CGRect)rect { UIImage *img = [UIImage imageNamed:@"RoseBunch.jpeg"]; UIGraphicsBeginImageContext(CGSizeMake(320, 480)); [img drawInRect:CGRectMake(0, 0, 50, 50)]; UIImage *resultingImage =

Using getRectsBeingDrawn: with Swift

安稳与你 提交于 2019-12-13 03:37:14
问题 I'm trying to use the NSView call getRectsBeingDrawn(_:count:) in a Swift app, but can't fathom how to unpack the 'return' values - the method's signature is particularly arcane. I'm getting the expected number of rectangles via the count variable, but I've no idea how to get access to rectangles in the array. This question addresses the same issue, and proposes a solution, but it's not working for me - I can't get access to NSRect structs. func decideWhatToRedraw() { let r1 = CGRect(x: 0, y: