cgcontext

Create new UIImage by adding shadow to existing UIImage

耗尽温柔 提交于 2019-11-28 07:02:05
I've taken a look at this question: UIImage Shadow Trouble But the accepted answer didn't work for me. What I'm trying to do is take a UIImage and add a shadow to it, then return a whole new UIImage, shadow and all. This is what I'm trying: - (UIImage*)imageWithShadow { CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef shadowContext = CGBitmapContextCreate(NULL, self.size.width, self.size.height + 1, CGImageGetBitsPerComponent(self.CGImage), 0, colourSpace, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease(colourSpace); CGContextSetShadow(shadowContext, CGSizeMake(0,

Setting A CGContext Transparent Background

时光毁灭记忆、已成空白 提交于 2019-11-28 05:39:48
I am still struggling with drawing a line with CGContext. I have actually go to line to draw, but now I need the background of the Rect to be transparent so the existing background shows thru. Here's my test code: (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextSetAlpha(context,0.0); CGContextFillRect(context, rect); CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor); CGContextSetLineWidth(context, 5.0); CGContextMoveToPoint(context, 100.0,0.0);

drawRect drawing 'transparent' text?

妖精的绣舞 提交于 2019-11-28 04:46:57
I am looking to draw a UILabel (preferable through subclassing) as a transparent label, but with solid background. I draw up an quick example (sorry, it's ugly, but it gets the points across :)). Basically I have a UILabel and I would like the background to be a set colour, and the text should be transparent. I do not want to colour the text with the views background, but instead have it be 100% transparent, since I have a texture in the background that I want to make sure lines up inside and outside of the label. I've been spending the night browsing SO and searching on Google, but I have

‘invalid context 0x0’ error when using CGContext* functions

非 Y 不嫁゛ 提交于 2019-11-28 01:19:17
/* Adding the Path */ UserGraphBuff = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(UserGraphBuff,5,10,0,1); CGContextSetLineWidth(UserGraphBuff, 2 ); CGContextBeginPath(UserGraphBuff); //line to last user point CGContextAddLineToPoint(UserGraphBuff, (*xVal)[sizeof xVal / sizeof *xVal - 1], (*yNewVal)[sizeof yNewVal / sizeof *yNewVal - 1]); //line to rest of user points in reverse order for (int i = sizeof xVal / sizeof *xVal - 1; i > -1; i--){ CGContextAddLineToPoint(UserGraphBuff, (*xVal)[i], (*yNewVal)[i]); } //EOFill CGContextEOFillPath(UserGraphBuff); Above is the code I am

Iphone CGContextShowTextAtPoint for Japanese characters

南笙酒味 提交于 2019-11-28 00:01:43
I am working on an app where I am using CGContextShowTextAtPoint to display text to the screen. I want to also display Japanese characters, but CGContextShowTextAtPoint takes as its input a C string. So either A) How do I change Japanese characters into a C string? If this is not possible, B) How can I manually print Japanese characters to the screen (within the drawRect method). Thanks in advance. Rhythmic Fistman CoreText can help you: CTFontGetGlyphsForCharacters (iOS 3.2 onwards) maps Unicode characters to glyphs CTFontDrawGlyphs (iOS 4.2 onwards) draws the glyphs into a CGContext. NB.

iPhone CGContextRef CGBitmapContextCreate unsupported parameter combination

匆匆过客 提交于 2019-11-27 23:47:18
In my application I need to resize and crop some images, stored locally and online. I am using Trevor Harmon's tutorial which implements UIImage+Resize . On my iPhone 4(iOS 4.3.1) everything works OK, I have no problems. But on my iPhone 3G (iOS 3.2) the resizing and crop methods are not working for any picture (the locally stored ones are PNGs). This is the console output: Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes

Doing Undo and Redo with Cglayer Drawing

随声附和 提交于 2019-11-27 16:20:21
I am working with a drawing app, I am using CGlayers for drawing. On touches ended, I get image out of the layer and store it in a Array, which I use to undo operation. My touches ended function -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"Touches ended"); UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawLayerInRect(context, self.bounds, self.drawingLayer); m_curImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [m_undoArray addObject: m_curImage]; }

Make 2 contradictory methods work in drawRect

江枫思渺然 提交于 2019-11-27 15:44:02
I'm writing an app building elements consisting of CGPoints. I have 2 buttons: makeRectangle and makeTriangle . For building/drawing stage I use three methods for rectangle and three methods for triangle inside drawRect . I'm stuck with my code in drawRect . In if-else-statement each method swaps the building/drawing scheme for previous element every time a button pressed. If I already have built rectangle and then I click makeTriangle button, I get new triangle but my rectangle turns into triangle with one unconnected point. Is there a workaround or I shouldn't use drawRect method? Here's an

Create a UIImage by rendering UIWebView on a background thread - iPhone

北城余情 提交于 2019-11-27 15:03:44
问题 Does someone know of a way, or has a creative idea as to how to obtain an UIImage that is rendered from a UIWebView? The catch is, that is must be on a background thread. I'll elaborate: I'm trying to obtain the image from multiple UIWebViews every second+-, and display it on screen (iPhone's of course). Because rendering a layer to a CGContext is a CPU consuming job, I wouldn't like to use the main thread, so not to hang the UI. My attempts so far were: I tried to use renderInContext on the

Using CGContext to display a sprite sheet iPhone

半城伤御伤魂 提交于 2019-11-27 14:15:19
问题 So I have a spritesheet in png format, and have already worked out the coordinates for what I want to display. I'm trying to create a method that will return a UIImage when passed the location information on the spritesheet. I'm just not sure how to use the CGContext stuff along with the the coordinates to return an UIImage. I was looking to CGContextClipToRect because I think that is the way to do it, but I just can't seem to get it to work. Something like this CGSize size = CGSizeMake(xSize