How to implement eraser functionality in DrawingApp? [duplicate] - iphone

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I implement a soft eraser stroke in a CGBitmapContext
How can I erase UIBezierPath lines drawn on a transparent view above an image?
In my Drawing app I want to implement Eraser Functionality.
If I have a white Background I will be erase that with change the color to white.
But, do I do if I have to erase the drawing on Background with photo?
How can I do that?

I believe that there are many possible solutions. One of them:
you create two layers (two images). One for the background, another for the drawn stuff.
when you "erase" you draw something. This something must mask background and
masked result must be drawn on the "stuff" layer.
Also you can play with masks, with blending options — I think every one of this features will allow you to implement "eraser" functionality.

Related

Create tintable image with solid colour, so that it can adapt Dark and Light modes

I need to create UIImage (bitmap?) filled with a solid colour so that it can be tinted and thus support Dark and Light mode changes
Is there a way to do this in Swift?
Not the best way, but a quick and dirty way to do this would be make a UIView with a background the color you want and then use one of the many ways to go UIView -> UIImage.
This stack overflow question here does exactly that:
How to convert a UIView to an image
Furthermore, looking at that code will give you some insights on how to do it the right way, with lower level graphics functions if you like.

iPhone Drawing Application (Not OpenGL)

I'm new to iPhone drawing field. I need to draw simple drawing on iPad. After I clicked button (that I created on same UIView)I need to erase those lines I was drawn.
In short;
Need to Draw a line.--> Click Button---> Erase those lines.
Now I Can draw A Line. But I want to erase those links and I fond useful links, for drawing and for erasing.
Question:
So How can I convert My Drawing image to CGImageRef ?
Is their any learning material for this ?
Is there any sample iPhone or iPad project for Drawing and erasing ?
Without Using OpenGl :)
Thank You.
Simple idea to perform erase operation is, set your current brush color to background color and this will virtually implements an eraser tool.
Draw a Line ---> Click on Eraser Button ---> use same paint method with background color(increased brush size)
Most of the drawing apps will use only white color as background, So that if you use white color brush for eraser with the same painting method will act as eraser. But if you use some other backgrounds like images you have to go for other methods.

iphone - Filling color in closed image

I'm trying to create an app for children. It will have different images. And those images will have different closed shapes like stars, balls or any other similar images.
I am aware of how to draw on iphone. I know how to select a color, how to change the brush size etc.
What I want to know is to select a color and on touch of image, it has to flood fill the closed area around touched co-ordinate. Is it possible? How can I do it?
(For example, if I touch inside the ball, the ball must be filled with one color)
check flood fill library
http://gauravstomar.blogspot.com/2014/09/uiimage-fill-color-objective-c.html
hope it will help
I think you need to use blending for that, see this answer:
Iphone App: How to fill an image with empty areas with coregraphics?

Modifying, coloring and dragging pre-existing images iPhone application

I am developing an iphone application which would let me modify the image by dragging other images over its top along with functionality that would let me choose a specific color from the image and replace it with some other color shades i choose. If anyone has some clue like how to actually implement it or some code, that would be great help for me to proceed in right direction
Thanks in advance :)
If you just want to overlay images, you can simply drag UIImageViews around and position them within the view hierarchy such that the appropriate images are overlaid one on top of the other.
For generating a new image out of those composited images, you may want to use something like CGContextDrawImage() within a UIView subclass's -drawRect: method or in a custom CGContext. You can also refer to these similar questions:
How can we combine images and get image object from this two images in iphone apps
Combining images
As far as selectively replacing a specific color within a UIImage, that's a commonly asked question here:
In a UIImage (or its derivatives), how can I replace one color with another?
How to make one color transparent on a UIImage?

UIKit. How to set Transparent color? [duplicate]

This question already has answers here:
How to make one color transparent on a UIImage?
(11 answers)
Closed 7 years ago.
Is there any way to set any color of UIImage (or it CALayer content) as transparent color?
I cannot use single image resource(PNG file) with built-in transparency.
I need to hide some area from first Layer by overlaying second Layer with specific color at that place. So I need to set this specific color as "transparent color" before assembled image drawing.
Image area I need to hide is like background - i.e. specific color will be started from image borders through whole perimeter.
Sounds like you need to use CGImageCreateWithMaskingColors. I recommend reading the "Bitmap Images and Image Masks" part of the Quartz Programming Guide, and check some example code. It's slightly more low-level than your average Cocoa code, but not very hard to accomplish.