I have two UIImageView with same frame. One imageView above second imageView now I'm erasing upper imageView using Core Graphics. My problem is that the border of eraser is very sharp I want faded border i.e. after erasing the upper image should match the lower one's pallet. See below example -
I used these two images and below is result -
As you can see in this image eraser's border is very sharp. I want to make it faded out like in the middle it should be dark then light then more light and so on i.e. we cant see the width and end of brush. And here is my - My Sample Code Let me know if my question is not clear enough.
You can have a png image like brush (dark in the middle and light in the corner) and draw the image over your image like this.
[eraser drawAtPoint:location blendMode:kCGBlendModeDestinationOut alpha:1];
Related
I have this PNG image: (the area in the grey borders is transparent)
I would like only the grey corners to have alpha of 0.5
If I set
[imgView setAlpha:0.5f];
Also the transparent area in the middle retrieves a semi-white color.
How can I do it?
Any reason why you don't just change the original image file? If that's not possible, you could put a white (black?) rectangle with 50% opacity below the image.
Of course there are many ways to do this but you would need to tell us more about your use case.
You should add one imageview below your desired image. and adjust alpha of that image.
I have a few questions on adding border to UIimage :
1) Is there anyway to add a dynamic border to an image of uiimageview?? I have tried to add border by using [layer setBorderColor:[UIColor whiteColor].CGColor]; But the border just shows around the frame of the uiimageview (a square or a rectangle). All my images are with thick black outlines and custom shape(such as hellokitty), I would like to add borders around the outlines. Is that possible to do it???
(I have also tried to add shadow around the images, but the result is too blurry, anyway to make them solid?? I think thats another way to solve my problem)
2) Also, if I can draw a custom shape border to stick around the images, is that possible to fill in color inside the border??, because some of my images have no filled color, any ideas??
Thanks in advance.
If your images are transparent with random shapes (i.e. the outline of the image is the shape of hello kitty) then I would approach this by...
First, ignore UIImageView here. Prob easier to create a custom UIView subclass.
In the drawRect of your view...
- (void)drawRect:(CGRect)rect
{
// calculate the rect of the image (aspect ratio etc...) so that it fits in the rect.
// see this link https://stackoverflow.com/questions/7645454/resize-uiimage-by-keeping-aspect-ratio-and-width
// change the colour of the image to black (or the border colour you want).
// see this link http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage
// draw the black image in the rect you calculated
// make a new rect that is smaller by in x and y than the one for the black image.
// You can change it by different amounts to change the border size
// draw the colour image in the new rect
}
Each step requires quite a bit of code so I've only put links and suggestions but this is what I'd do if I was trying to do what you are doing.
Link 1 - Resize UIImage by keeping Aspect ratio and width
Link 2 - http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage
I realised that all my png images are defined with a transparent color instead of white color. I never noticed because the background of my app was white but now is of a different color. And as I cannot edit each single png file to replace the transparent color to white, I am looking for a simple programmatic way of replacing on the fly the transparent color by a white color. How should I do this please?
Thanks for any help
Cheers,
geebee
If I understand what you're trying to do, I would suggest you add a white background to your UIImageViews.
self.myImageView.backgroundColor = [UIColor whiteColor];
I don't see why you can't just "edit each single png file"; it's a pretty much instant batch operation using GraphicConverter or ImageMagick or whatever.
If you really insist on compensating for this on the device when the image loads, then just draw the image onto a white opaque rectangle and use the resulting composite image.
I want to put a watermark on a UIImageView. I have two watermark images, a black one and a white one. I want to put the black one on the UIImageView when the area of the watermark is bright, and the white one on the UIImageView when the area of the watermark is dark. How to do that?
Any help would be appreciated.
Perhaps you should consider having a single watermark that looks ok on all backgrounds, like a transparent white with opacity or grey color with a drop shadow. This seems like less hassle than trying to programmatically determine relative brightness on an image.
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.