I need to grab the scaled image of content currently visible in UIScrollView. I'm able to get the image but there is discrepancy between anti-aliasing algorithm used by scroll view and the grabbing process. Please look at the image to get my point:
(left: as seen in UIScrollView, right: as grabbed with renderInContext)
the image
I already tried to set interpolation quality, edge antialiasing mask and allow/force anti-alias in context using CGContextSetAllowsAntialiasing and CGContextSetShouldAntialias without success. The image is saved to file as an PNG with UIImagePNGRepresentation.
Any ideas how to grab the exact copy of what is visible in scroll view?
Related
I have a bunch of round Images. They are in png with a 512x512 size. I took them from Flaticon.
To display images in a tableView I use imageView with a 45x45px size and Content Mode as Aspect Fit. Images put in a project assets.xcassets folder with a Scale property as Single Scale.
When images displayed by a tableView a jaggy border is visible in every image:
And its visible without zooming in:
Is it a problem with source images? How to make the image border smooth?
The issue is with an image that you have added.
Please use a normal image and give corner radius to image view as below
self.imageFlag.layer.cornerRadius = self.imageFlag.frame.size.height/2
This will resolve your issue
Below is the screenshot
My app lets users choose or take a picture then add other objects or text on top and rotate/resize them.
For saving i'm just taking a screenshot of the iPhone screen because after trying for hours and hours I just couldn't figure out how to save the original image with the added objects being placed at the right spots, with the right rotation/resized/etc... (If anyone knows a good example/tutorial of how to do this it would be incredibly helpful!)
I have a UIView with a size of 320x366. When user chooses an image I load it inside that UIView and it gets sized to fit properly with it's aspect ratio. When the user is done adding/editing objects on his image he can then save it.
-(UIImage *)createMergedImage
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(contentView.frame.size.width, contentView.frame.size.height), NO, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, CGRectMake(0, 0, contentView.frame.size.width,contentView.frame.size.height));
//contentView is the 320x366 view with all the images
[contentView.layer renderInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenShot;
}
That's the code i'm using to save the UIView as a picture. Fitting the images with their correct shrunk aspect ratio, there's either transparent border at the top/bottom or left/right.
Now it's saving and works, when I open the image it's exactly what i'd expect. The problem is when i'm looking at the preview image, it shows other images (that i've previously seen on my iPhone) in the transparent part of the picture. As you can see in this following image.
When I go in the Camera Roll the transparent part looks black (like it should) as seen in this second image.
Also when i'm scrolling through my Camera Roll when I get to the image that my app saved, i'll see those extra random images in the transparent area for 0-1 secs before it disappears and becomes black (leaving the correct image the way it should be).
I'm hoping someone has seen something like this before and knows how to fix it.
Thanks!
I'm using UIImagePickerController class to capture image from camera.
When is captured, I save the picture on disk. After that I use imageWithContentsOfFile method to load this image as background of the main screen.
The problem is that when I load the picture appears 2 white bands on top & bottom of the view.
My question is how can I take a picture with 320X480px of size in order to load it full screen?
Thanks.
--EDIT--
The originalImage when is captured sizes this:
INFO -> Captured Image Size W:480.000000 H:640.000000
How can I get the image directly 320X480px?
Thanks.
Presumably you get white bands because you've got the content mode of the UIImageView you're displaying it in set to UIViewContentModeAspectFit which means resize the image, maintaining aspect so that it you can see the entire image. If you set the content mode to UIViewContentModeAspectFill it'll do what you want.
The reason for this discrepancy is that the aspect ratio of the screen (2:3) is not the same as the aspect ratio of the images that come from the camera (3:4).
I'm trying to achieve a sort of dynamic UIView masking effect. Here is a sketch:
So as you can see, I'm trying to create a UIView that can effectively cut through an image to reveal the image behind it. I already know how to return an image with a mask statically, however I would like the "revealer" to be draggable (I'll use pan gesture) and live.
Does anyone have any ideas or starting points on how to achieve this? Thanks
(NOTE: My demo says White layer, but I'd actually like to show another image or photo).
masking an image is not that difficult.
This link shows the basics.
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
But personally I think i would make 2 UIImage views and crop the content of the draggable UIView. I'm not sure but I would expect that clipping and panning the second image will be less computationally expensive then applying the mask and will get you a better frame rate.
So I would do: UIImageView of the full image. A UIView on top of it with a white and some transparency setting to make it look white, then a UIImageView with the image either places or cropped so that only the correct section is showing.
I am using a custom image as the background image for my buttons. I have noticed that the edges of the buttons are cut off sometimes. My buttons vary in size but the behavior doesn't seem to be dependent on the button size. I am creating the buttons programatically. The image I am using is pretty large to cover the entire background.
Can someone please let me know what could be the issue?
More info
Setting the content mode to UIViewContentModeScaleToFill still cuts of the images. Also tried resizing the image but doesn't make a difference.
Thanks.
Did you try setting the button's dimensions to fit exactly the image?
Is the image just cropped or also blurry (cause it's being resized)? Have you toyed around with UIView's contentMode property for the button?
If you did, did you try increasing/decreasing the width or height by a pixel? I sometimes had blurry buttons even though its dimensions were exactly the image's. Adding or removing an extra pixel sometimes helped.
I finally resolved this by creating a 3x3 px image with the background color as the button's color and a 1 px border surrounding the image. Then used the UIImage method stretchableImageWithLeftCapWidth:topCapHeight: to create an image with the desired border size of 1 px.