UIKit. How to set Transparent color? [duplicate] - iphone

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.

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.

invert colors of Image [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
UIImage color changing?
I have one image with Grey and white color.I want to change Grey color to white and change white color to Grey through code dynamically. Please help.
Better to look out for Open CV framework, because the thing which you are expecting in already available with this framework.
You can get the source from here
Sample Code : Convert RGB to Black & White in OpenCV
Convert image document to black and white with OpenCV
Hope that would give you some new idea about image processing. :)

How to implement eraser functionality in DrawingApp? [duplicate]

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.

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?

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.