CGContext transparency problem - iphone

I have an UIView which has white background color set.
I have set the blending mode of the CGContext of the UIView as 'kCGBlendModeCopy'.
Then,
1. Draw an UIImage in that CGContext
2. Draw a path with alpha as 0 in that context.
The transparent area covered by the path appears in black whereas my expected output was that it should be UIView's background color (i.e. white).
Does anyone knows what is the problem here?
Thanks in advance,
Regards,
Deepa

There is no problem here and hence no solution. Since we are drawing on the UIView's context with transparency, we can see the screen that is in black color. The drawing hierarchy is like this:
1. Black screen
2. On this transparent window is kept. Through this window we can see the screen
3. A view that is partially transparent is kept on this window. Through this view we can see window(Window is transparent and hence we can see screen)
(View is partially transparent because I am drawing part of the View with transparent path)
Hope this helps you Naren

Maybe this article can help you..
http://losingfight.com/blog/2007/08/18/how-to-implement-a-basic-bitmap-brush/

I understood the problem after putting some more effort:
CGContext is not a separate drawing layer of UIView. UIView is a cocoa wrapper for CGContext drawing. Since I am drawing the path with transparency, the screen behind the UIView is visible.

Related

The surounding area of an ellipse is black. Why?

I am drawing an ellipse using core graphics in iOS. The area near the corners of the ellipse are black in color. I want it to be clearColor. How do I get about this?
CGContextAddEllipseInRect(context, ellipseFrame);
CGContextSetFillColorWithColor(context, fillColor);
CGContextFillEllipseInRect(context, ellipseFrame);
I am sorry. I don't have enough reputations to add the screenshot of my output.
Clear the context before you start drawing:
CGContextClearRect(context, ellipseFrame);
If you are drawing ellipse in drawRect method of UIView subclass,
the area near the corners of the ellipse must be taking the background color of UIView.
Setting its backgroundColor to clearColor should sove the issue.
In UIView or NSView you draw from back to front.
You can think of the code you write in drawRect: as procedural back to front drawing instructions.
If you see black corners you probably have a containing view that is isOpaque or need to first do [[NSColor clearColor] fill] before subsequent drawing in drawRect:

Coloring in images transparent part in imageview

The following images brown color part is transparent ,i tried coloring with the refrence http://www.edumobile.org/iphone/iphone-beginner-tutorials/digital-signature-application-in-iphone/,
Is it possible to coloring only at transparent part in the uiimage view?
The very simple solution is to have a UIView behind your UIImageView, make sure the UIImageView has a background set to Clear and then you'll be able to see what ever is in the background view through the transparent area of the image.
Check out Mike Ash’s Implementing a Flood Fill and Optimizing Flood Fill. You’ll have to swap out the NSGraphicsContext stuff for CGContext.

Hide / reveal UIImage based on finger path?

I hope that makes sense. I'll try to explain it.
I have a UIImageView on screen, and am wondering how I can take the area after "drawing" on it with a finger, and remove that section from the UImage, or, create a separate UIImage from the selection.
I'm not looking for code (unless you have it =] ), just an idea of how to go about doing it. If you have tips, I'd be very grateful, thanks.
If I understand your question,
I think I would add a transparent UIView as a subview over the top of the UIImageView. And draw on that. Then you can remove/hide the subview when your done.
you need to create a UIGestureRecognizer with target and a action like -imageIsPressed, in this -imagePressed method you can call something to make the image disappear. I would suggest placing the UIImage into a UIImageView and calling imageview.hidden = YES; to hide the image, and set it back to "NO" once its not held by the finger.
You'd need to implement something that captures the area the user 'selected' (maybe be creating a CGPath. Then you create a CALayer of the size of the imageView. In it you create, draw and fill the captured path with some arbitrary color while leaving the rest transparent. Finally you apply your generated CALayer as a mask to the UIImageView:
imageView.layer.mask = maskLayer;
Hope that gets you started.
For more info on how to draw that custom CALayer pls refer to Quartz Programming Guide
So basically you want to implement freehand erasing of an image? You will need to use core graphics and the various CGContext methods (with blend mode set to clear) to achieve this. There are two approaches, but both start with drawing your image as the first part of drawRect, and then
1) Store your strokes in an array, and stroke all of them over top of the image.
2) Stroke one stroke over the image and then store the resulting image into a UIImage. Use this UIImage as the next image that you draw in drawRect. This one is difficult for undo/redo functionality.
I recently implemented this myself and made the source available here. Basically I used the same methods described here with this change when setting up the graphics context:
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);

How do I blur whatever is behind a translucent UIImageView?

I have a translucent png image (made by turning down the opacity in Photoshop), and there's a UIImageView behind that translucent image. Is there any way to blur the parts of the UIImageView on the bottom that intersect with the UIImageView on top? Thanks!
Not aware of any code that will do that on its own, but you could 'fake it' by rendering the intersection of the views in a graphics context, then apply a blur effect to it. Then you could take the graphics context and insert a UIImageView with the resulting image in between the two views to simulate the effect. This method would not work very well if you have any sort of animation or otherwise changing the state of the images.
You may try setting alpha of the image to less than 1.

Why does UIImageView appear to be partially transparent

I have a simple app that just displays a UIImageView. For some reason the image appears that it is partially transparent as it is much lighter than if I view the same image in photoshop. Any suggestions...I though by default a UIView is opaque.
You have probably changed the alpha of your imageView or the view itself. check for the the transparency of your imageview also. Because the default alpha of the imageview is 1 and opacity is also set to 100%. You might have chane one of these otherwise this is the problem of your image only
I don't believe that UIImageView is by default partially transparent? Try changing the background colour of the application and see if that affects the outcome of your image, if it is transparent it should be darker with a black background rather than white.