iPhone Drawing Application (Not OpenGL) - iphone

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.

Related

Gradient texture background

I want to create a dark grill texture that fades to black for a configuration screen under a page curl effect.
Garmin StreetPilot Onboard uses something like this:
http://www.pcmag.com/slideshow_viewer/0,3253,l%253D286397%2526a%253D286507%2526po%253D7,00.asp?p=n
How do I programmatically create a background such as this? I really don't want to include an image the size of the iPhone screen; this seems the lazy approach.
I would create it in two parts. First, draw a gradient using the normal quartz drawing functions. Then, add an overlay with a repeating pattern of dots. These dots could be a small PNG file that is tiled, or you could use quartz to draw them.
See the documentation for CGContextDrawLinearGradient and [UIColor initWithPatternImage:]

How to erase foreground image to make the background visible using OpenGLES?

I'm learning iPhone development specifically OpenGL ES 2. I'm trying to achieve an effect as in steam draw. I have a background image and a foreground image. When I move the finger over the foreground image the corresponding pixels of the foreground image are erased and the background does get visible. Can someone point me in the right direction on how to implement this? Some guide lines?
You can use GL_STENSIL_TEST when drawing foreground to exclude fragments you choose(or your finger ;))

Convert an image to an iPhone toolbar icon

I have a grayscale icon that I'm editing with Photoshop with a transparent background, but I can't, for the life of me, figure out how to convert the icon to one that can be used as an iPhone toolbar icon. If I simply save the image as a PNG, it doesn't show up as anti-aliased on the iPhone because every pixel with color is being rendered as black, instead of a shade of gray.
According to the Apple docs and other sources, there needs to be an alpha channel on the image to specify varying levels of transparency for each pixel. However, I have no idea what that means. I've read these posts and docs from Adobe and I still can't figure out how to properly convert a grayscale image into one that can be used as an iPhone toolbar icon. The blog post is hard to comprehend and poorly written, and the Adobe docs don't really help.
http://cahit.hayalet.net/blog/514/converting-an-image-to-iphone-toolbar-icon/
http://livedocs.adobe.com/en_US/Photoshop/10.0/help.html?content=WS74B356C9-353F-4483-8632-7B1A102F2A2E.html
Can someone point me in the right direction or provide exact, step-by-step directions to doing this in Photoshop?
It's much more simple than having to muck with actual masks in Photoshop.
iPhone toolbar icons are about 30px by 30px, so make a new Photoshop file with those dimensions. Ensure the background is transparent (you can specify that when creating a new file).
Then, any pixels you draw on top of this transparency become what iOS uses for the icon. Doesn't matter what color it is in Photoshop for NSToolbar icons -- they're automatically used as masks by iOS.
Leave transparent the parts you want to show through. Save as 24-bit PNG, and chuck into XCode as usual.
For a few icons that serve as good starting examples, check out the ones I publish for free here: http://glyphish.com Just take one of the PNGs and open it in Photoshop and you'll see that it's drawn in an arbitrary color (#444444) with varying levels of opacity to create darker and lighter parts of the icon.
This is more of a photoshop question than coding but anyway, here's a suggestion.
Lunacore has a good tutorial on how to use masks.
What you want to do is:
Make sure you're background is transparent.
Create a new layer and
fill it with any solid color.
Create a mask on the solid color
layer, and fill your greyscale image into the mask. (Use your
greyscale image as the mask.)
Toolbar icons use your image as a mask. They only consider what transparancy the image has. Not what color or shade.

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.

How can I 'shine' a png on the iPhone in the same way that the app launcher does?

I want to show users what their square flat .png image will look like when converted to a normal 'shined' icon by the app launcher.
e.g. round corners and glassy effect.
Thanks
For in-application representation of the 'shine' on an icon, you can create a custom UIView that draws the shine gradient, using the code here (adjusting the gradient colors to match Apple's). When you want to apply the 'shine' to the preview icon, just overlay this custom UIView on top of its UIImageView (or whatever you're hosting it in).
The rectangular clipping could be a little trickier. If you have a solid black background, you could overlay a frame UIImageView that has a black area with a rounded rectangular transparent region in its center. You can also do this in a more general-purpose manner via Core Graphics by drawing your image and the gloss into a view, then using CGContextClip with a rounded rectangle to carve out the rounded interior.