core-graphics

UIImage decompression causing scrolling lag

时光怂恿深爱的人放手 提交于 2019-12-03 02:44:37
问题 I have this app with a full screen tableView that displays a bunch of tiny images. Those images are pulled from the web, processed on a background thread, and then saved to disk using something like: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0); // code that adds some glosses, shadows, etc UIImage *output = UIGraphicsGetImageFromCurrentImageContext(); NSData* cacheData = UIImagePNGRepresentation

How can I change the saturation of an UIImage?

你离开我真会死。 提交于 2019-12-03 01:16:00
问题 I have an UIImage and want to shift it's saturation about +10%. Are there standard methods or functions that can be used for this? 回答1: There's a CoreImage filter for this. CIColorControls Just set the inputSaturation to < 1.0 to desaturate or > 1.0 to increase saturation... eg. Here's a method I've added in a category on UIImage to desaturate an image. -(UIImage*) imageDesaturated { CIContext *context = [CIContext contextWithOptions:nil]; CIImage *ciimage = [CIImage imageWithCGImage:self

3d text effect in iOS

别来无恙 提交于 2019-12-03 00:56:52
问题 I want to render some text on one of my screens that has a 3dish look to it. I am using UIKit and standard views controllers etc. The effect will look something like this: Can this be done somehow with UIKit & iOS? Ordinarily I would just use a static png however, the text is dynamic and updates based on user data 回答1: The following code might not be perfect, but it should be a good starting point. Basically you draw the font twice, slightly changing the size and the offset. Depending on the

Just in theory: How is the alpha component premultiplied into the other components of an PNG in iPhone OS, and how can it be unpremultiplied properly?

亡梦爱人 提交于 2019-12-03 00:50:59
Actually, I thought that there would be an easy way to achieve that. What I need is pure alpha value information. For testing, I have a 50 x 55 px PNG, where on every edge a 5x5 pixel rectangle is fully transparent. In these areas alpha has to be 0.Everywhere else it has to be 255. I made very sure that my PNG is created correctly, and it also looks correctly. Please tell me if this is theoretically correct: I created an CGImageRef that has only the alpha channel and nothing else. This is done with CGBitmapContextCreate and kCGImageAlphaOnly as param. CGBitmapContextGetBitsPerPixel(context)

“renderInContext:” and CATransform3D

左心房为你撑大大i 提交于 2019-12-03 00:46:00
I have an view that have mutiples views inside it, and an image presentation (aka. 'cover flow') into that too... And I need to make a screenshot programatically ! Since docs says that "renderInContext:" will not render 3d animations : "Important The Mac OS X v10.5 implementation of this method does not support the entire Core Animation composition model. QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer layers are not rendered. Additionally, layers that use 3D transforms are not rendered, nor are layers that specify backgroundFilters, filters, compositingFilter, or a mask values. Future

How to store CGRect values in NSMutableArray?

做~自己de王妃 提交于 2019-12-03 00:37:21
问题 How would I store CGRect objects in a NSMutableArray, and then later retrieve them? 回答1: You need to wrap the CG structures in NSValue classes. So: NSMutableArray* array = [NSMutableArray mutableArray]; [array addObject:[NSValue valueWithCGRect:CGRectMake(0,0,10,10)]]; CGRect someRect = [[array objectAtIndex:0] CGRectValue]; 回答2: CGRect rect = CGRectMake( 5, 5, 40, 30 ); NSString* rectAsString = NSStringFromCGRect( rect ); CGRect original = CGRectFromString( rectAsString ); What do you think

CALayer: Single pixel line looks like 2 pixels

北慕城南 提交于 2019-12-03 00:28:40
This is my code: int columns 3; int columnWidth = self.layer.bounds.size.width / 3; for (int c = 1; c < columns; c++) { CALayer *layer = [CALayer layer]; layer.frame = (CGRectMake(columnWidth * c + 0.5, 0.5, 1, self.layer.bounds.size.height)); layer.backgroundColor = myColor; [grid addSublayer:layer]; } I understand that I have to shift the x and y 0.5 pixels, which is what I have done, yet it still shows as a 2 pixel line instead of 1. Set the layer Frame as layer.frame = (CGRectMake(columnWidth * c + 0.5, 0.5, 0.5, self.layer.bounds.size.height)); Yeah it will work for retina also Check this

Draw a perfect circle from user's touch

不问归期 提交于 2019-12-03 00:01:47
问题 I have this practice project that allows the user to draw on the screen as they touch with their fingers. Very simple App I did as exercise way back. My little cousin took the liberty of drawing things with his finger with my iPad on this App (Kids drawings: circle, lines, etc, whatever came to his mind). Then he started to draw circles and then he asked me to make it "good circle" (from my understanding: make the drawn circle perfectly round, as we know no matter how stable we try to draw

iOS Colors Incorrect When Saving Animated Gif

限于喜欢 提交于 2019-12-02 23:56:54
I am having this very strange issue. I am creating animated gifs from UIImages and most of the time they come out correct. However when I start to get into larger size images my colors start to disappear. For example if I do a 4 frame 32 x 32 pixel image with no more than 10 colors no issue. If I scale the same image up to 832 x 832 I lose a pink color and my brown turns green. @1x 32 x 32 @10x 320 x 320 @26x 832 x 832 Here is the code I use to create the gif... var kFrameCount = 0 for smdLayer in drawingToUse!.layers{ if !smdLayer.hidden { kFrameCount += 1 } } let loopingProperty = [String

Why does drawRect: work without calling [super drawrect:rect]?

安稳与你 提交于 2019-12-02 23:51:35
I'm overriding drawRect: in one of my views and it works even without calling [super drawrect:rect]. How does that work? - (void)drawRect:(CGRect)rect{ CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetBlendMode(context, kCGBlendModeDestinationOver); [[UIColor clearColor] setFill]; UIRectFill(CGRectMake(0,0,100,100)); } Shanti K From the documentation: "The default implementation of this method does nothing.Subclasses that use technologies such as Core Graphics and UIKit to draw their view’s content should override this method and implement their drawing code there" Also from