While developing a photography based app i need to rotate an image. But after rotating an image it's border gets fuzzy. i have attached screen shot of this..
As you can see first image looks good but other images which are rotated are not looking good.
here is my code.....
[img setBackgroundColor:[UIColor blackColor]];
[img setContentMode:UIViewContentModeScaleAspectFit];
[img.layer setBorderColor:[[UIColor whiteColor]CGColor]];
[img.layer setBorderWidth:3.0];
[img setTransform:CGAffineTransformMakeRotation(rotation*3.14/180)];
I have used this solution...
CGContextRotateCTM(context, radians);
[sourceImage drawInRect:rect];
But how to work with this code when image has boarders.
Please give your valuable response .....
When you rotate an image the border pixels are not antialiased: See this question.
The solution, as odd as it sounds, is to give the image a 1px transparent border. This answer gives the code to add the 1px transparent border to your image.
Its because of aliasing effect. Search for "anti-aliasing".
Related
I'm trying to make a UIImageView with round corners, so I used [imageView.layer setCornerRadius:5.0f]; it works but not perfectly.
If you look closely, you can see the corners of the image(I uploaded a photo, I don't know if you can see it clearly, there are blue parts in the corners). How should I remove these? thank you.
(P.S.: I also set the border of the view, is that the reason why?)
UIImageView doesn't clip to bounds by default. So while the corner radius is applied its still drawing outside of its designated area.
objc:
[imageView setClipsToBounds:YES];
swift:
imageView.clipsToBounds = true
I am using AQGridView in my project. we need to create a black colored border around each image. Can anyone help me on this.
Thanks in advance.
Regards,
Jas.
for UIImageView it is like something :-
[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
Hope it works on AQGridView...
Cheers
You could also put your AQGridView in a larger UIImageView that was empty but had the background set to black.
I have a box that i want to be expanable only on its width, while still maintaining the rounded corners that I have. I made the graphic in photoshop. and it is exactly 13px wide, so 6 for each corner and 1 for the middle to repeat.
UIImage* img = [[UIImage imageNamed:#"screen_displayer_rounded.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:6];
CGRect rect = CGRectMake(272.0f, 14.0f, 100.0f, 30.0f);
UIImageView* imgView = [[UIImageView alloc] initWithFrame:rect];
[imgView setImage:img];
Could anyone tell me why this might be happening?
Thanks!
I have found that you cant just rely stretchableImageWithLeftCapWidth to get it to resize correctly.
I normally use the contentStretch property that is available to all UIView subclasses when stretchableImageWithLeftCapWidth doesnt work for me.
Checkout the UIView apple docs regarding the contentStretch property.
You should check if the view doesn't end up at a non-integer position. If you choose "Run with performance tool > Core Animation" and check "Color misaligned images", all misaligned images will show purple.
If your image is purple, try to find out which superview is causing this. Look out for things being centered, since that is a common cause for these issues.
Just checking - are you perhaps viewing a non-retina image on a retina display? This would definitely stretch it out.
I am using PNG images to add icons to the rows in my tableview, using
[cell.imageView setImage:[UIImage imageNamed:#"chart.png"]];
This was not a problem before, as my images had black edges and my tableview had black rows. However, I am now providing a light color style as well as dark. So the black edges look rough.
So I thought I would draw the images with a black background.
However, I don't know how to do this?
UIImageView inherits from UIView so you can just set the backgroundColor property to show a color behind the transparant parts of your png image
[cell.imageView setBackgroundColor:[UIColor blackColor]];
In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this:
[[UIColor colorWithWhite:0.0 alpha:0.2] set];
UIRectFill(rect);
The problem is, that the alpha property seems to get ignored. No alpha is applied at all, just a black rectangle is drawn. How can I fix this? Thanks in advance!
Use CGContextSetBlendMode() before you draw the rect.
Set your view background color to transparent… It should work.