How can i paint inside the bouandry of the PNG image - iphone

I have an PNG image with complete transparency. It has a picture of an animal , just bordered with black color.
Now , I want to paint the image as my finger move on the ipad Screen, but paint should only appear inside the bordered region not out side.
My Thinking -----
What i am thinking is to keep the color of the image inside the boundary line, a little bit differ from the out side. Then, Get the pixel of the image and for each pixel , the color component.
Keeping all the pixels of out side the boundary in an array and check for it when finger move on the iPad screen.
I am new to the concept of core graphic and open GL so not being able to think wisely. Please help.

First you should define where is "inside" to paint on your image.
I suggest to run a flood fill algortihm on the first touched place and define de desired "inside area" pixels. Notice that you will run the flood fill at the background on the original black and white image, not for actually painting the pixels, just to figure out the target ones.
For example; we want to paint the animals face and body to different colors. When user first toucehs the face and drags over, you can do a flood fill on black and white image to find the pixels of the face and only paint the intersection of the face area and the touched area. Then, when the user picks up her finger (changes the color) and retouches on the body and you do another flood fill operation to detect the pixels of the body and so on.
It was a long description, hope it makes sense.
Here are some flood fill sources that might help:
Floodfill in objective c
https://stackoverflow.com/questions/8121348/flood-fill-algorithm-objective-c-version
How to Implement FloodFill Algorithm in iphone

Related

Flutter change transparency of png image with finger touch

I have a png image with transparent areas and opaque areas.
I want to be able to draw with my finger, with GestureDetector for example, on that image to be able to add transparency in the opaque areas and add opaque areas in the transparent areas. Both. For example with a button that allows you to switch between erase and paint modes.
The objective is that it can represent two images on the screen, inside a stack, one after the other. The back image is completely opaque and the front image has areas with transparency and you can paint over it as I mentioned before. In this way, as you add transparent areas in the front image, what is in the back image will be revealed. And conversely, you can add opacity to the image so that the image behind is hidden by the image in front.
I've tried CustonPaint but it's very difficult since you would have to add the image with drawImage, and do a lot of complicated steps. And I couldn't change the transparency of the image either, also, even if I could, with CustonPaint if you draw a lot, the screen slows down.

Unity 2D display "flash effect" above tiles

I want to apply a brighten effect above my scene.
My scene contains tiles, and I want to perform white flash for a few frames by code.
I have already tried this code:
private Tilemap tm;
...
tm = GetComponent<Tilemap>();
tm.color = new Color(0.5f,1.0f,1.0f,1.0f);
This code darkens the scene by a certain color amount, but I wish to brighten it.
Your code is not working because in Unity if you render an image (in your case tile) the original color of the image is when its color is white (255,255,255,255).
It means that if you change the color of an image it will add this color to this image.
For instance, if you set the color of an image to red, the image colors will become more similar to red than the original image.
As I see it you have 2 ways to perform the white flash:
A) Add another image of a white rectangle that covers all the screen and set it's alpha color to a low number (the lower the number the lighter flash effect).
In the editor disable this object's renderer and when you want to perform a flash effect enable this object from the code (You can improve this with animations or code to get a smooth flash animation).
B) Install the package "2D Light". This is an experimental package that allow you to render 2d light.
This package contains a lot of components that allow you to stimulate light.
I have found a way to do this.
I created a new PNG that only contains white shapes on a transparent background.
There are about 20 pieces that match the shapes of my level tilemap.
Now I just create a new (white) tilemap above the level tilemap in the shape of the highlight.
Then I set the alpha of the white tilemap in code.
It works :)

How to trace the intersection of an image with the boundaries of an irregular shaped image in cocos2d?

I have an image of mountain with small gutters and tunnels in it. I want to pass a small image through that tunnels. How to trace the intersection of that small image with the exact boundaries of large image in cocos2d?
I would make a collision mask for this.
What this means is to create an exact copy of the image you are using for your terrain except make it only two colors: white and black.
Make the areas that you want the player to be able to move through (not walls) white. Make the walls and anything you want the player to collide with back. Next, just do some pixel collision detection. To do this, I would get the RGB (not RGBA because alpha doesn't matter) data. Loop through this data (or a section of it for better performance) and detect whether or not the player is on a black or white pixel.
Do whatever you need to accordingly.
If you need more help, feel free to ask.

ios game make a mask layer effect

I need a 'mask' layer that covers the whole screen, with the center part (a circle) to be transparent. Then I can move the mask layer around using touch. User are only able to see the transparent part in the middle.
I don't think a png file can help because the file need to be very large to cover the whole screen.
So is it possible to do it by coding?
i found this online, but don't know much about openGL. http://www.cocos2d-iphone.org/forum/topic/7921.
it would be great if i can use a CCMaskLayer and input with the radius. i can handle the touch event by my self.
the attached png file is expected result, the center part is transparent. i need this to cover my screen, and only show the middle part. the red part is covered.
I write a CCMaskLayer to do the exactly same thing.
https://github.com/smilingpoplar/CCMaskLayer
You may solve this task with cropped circle texture in two ways:
1) Draw sprite with circle texture in screen center and draw another 4 sprites around (on top, bottom, left and right sides) with small red texture but scaled to cover all screen.
2) (more elegant but harder to implement) Make your mask layer fullscreen but adjust texture coordinates. In details:
set wrap mode to GL_CLAMP_TO_EDGE to your circle texture
adjust texture coordinates of your layer vertices (to do this you need to subclass base CCLayer):
Here v means vertex position and t - texture coordinates. You need to set correct texture coordinates for four corner vertices of layer. For future if you will want to drag circle you will need to add some offset values to texture coordinates.

Coloring Image in iPhone SDK

i am developing a iphone app. i have a background image lets say an airplane with black color out lines and from color palette user can pick a color and fill the region of airplane....any help, code , suggestion will highly be appriciated
A simple fill algorithm should do. just expand from the point you are on until you meet region end pixels
see http://en.wikipedia.org/wiki/Flood_fill you can also try googling for Boundary Fill algorithm
My first though was to have a UIView and a mask image on top of that with the plane but this only works in certain situations. If the shape of the plane does not change you could also change the color and then "fill" the plan in during the drawRect using functions like CGContextAddArc and CGContextAddRect.