I am making UIImage from CGIImageRef.
CGImageRef drawImage = CGImageCreateWithImageInRect(croppedImage.CGImage, frame);
UIImage *newImage = [UIImage imageWithCGImage:drawImage];
CGImageRelease(drawImage);
And applying it to Image View:
self.imageview.image = newImage;
After this line self.imageview.image = imgV.image; my imageView is resized to size of UIImage(newImage).
When I log my self.imageview frame then I am getting correct value. I am not able to get exact reason behind this.
UIImageView will be autoResize to fit its image size if u didnt set the frame of imageView
Related
i have one image as 640*960,and my image view has 300*300.i set the content mode the image view as aspect fit, now i load the image to the imageView it looks follow..
after loaded the image to the image view i need the width and height of the image from the imageView.
Did you try?
#import AVFoundation;
UIImageView *image = [[UIImageView alloc] init];
image.image = [UIImage imageNamed:#"paint5.png"];
CGRect yourFrame = AVMakeRectWithAspectRatioInsideRect(imageView.image.size, imageView.bounds);
NSLog(#"%#",NSStringFromCGRect(yourFrame));
I think thats what u are looking for.
AV Foundation Functions Reference
You can get height and width of image in following way:
UIImageView *image = [[UIImageView alloc] init];
image.image = [UIImage imageNamed:#"paint5.png"];
int imgHeight = image.layer.frame.size.height;
int imgWidth = image.layer.frame.size.width;
NSLog(#"height of image %i",imgHeight);
NSLog(#"widht of image %i",imgWidth);
I am trying to resize UIImage . i am taking the image and set its width to 640(for ex), and check the factor i had to use, and use it to the image height also .
Somehow the image is sometimes flips, even if it was portrait image, it becomes landscape.
I am probably not giving attention to something here ..
//scale 'newImage'
CGRect screenRect = CGRectMake(0, 0, 640.0, newImage.size.height* (640/newImage.size.width) );
UIGraphicsBeginImageContext(screenRect.size);
[newImage drawInRect:screenRect];
UIImage *scaled = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Ok i have the answer but its not her.
when i took the image from the assetLibrary i took it with :
CGImageRef imageRef = result.defaultRepresentation.fullResolution;
This flips the image, now i use :
CGImageRef imageRef = result.defaultRepresentation.fullScreenImage;
and the image is just fine .
I have one UIImageView which is in scale to fill mode. Now i want to crop the image in imageview. I have one rectangle on this imageview which user can move and change the size. After particular size is selected i want to crop the image using this frame. But since my mode of uiimageview is scale to fill this messes the cropping rectangle and different part is cropped. Has any one faced this problem. How to crop properly ?
Your options are to calculate, or use this walkaround:
-(UIImage *)imageFromImageView:(UIImageView *)view withCropRect:(CGRect)cropRect
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * largeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([largeImage CGImage], cropRect);
UIImage* img = UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return img;
}
I have an uiimageview that is 600x600 and a uitexview loaded in a 200x200 uiview.
I would like to export this uiview to 600x600, same as the uiimageview size.
However If I use the code below I can only generate a size of 400x400, that is the retina size of the uiview.
Is there any code I can achieve this?
UIGraphicsBeginImageContextWithOptions(outputView.bounds.size, outputView.opaque, 2);
[outputView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Have you tried changing the bounds of the view to what you need?
outputView.bounds = CGRectMake(0,0,600,600);
UIGraphicsBeginImageContextWithOptions(outputView.bounds.size, outputView.opaque, 2); [outputView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
outputView.bound = ... original bounds here ...
If the internal view is set to be resized automatically, this should work seamlessly. Otherwise, you could change the frame of the internal view as well.
You could use the UIImage category of AliSoftware to resize it
I have a app that will populate a UITableView after the user takes a picture.
The UITableViewCell's image is that picture that the user takes. I would prefer these images to be square.
I have tried just about everything, here's some code:
UIImage *theImage = [UIImage imageNamed:theImagePath];
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.image = theImage;
Thanks!
Coulton
one option would be to pass in a square image:
UIGraphicsBeginImageContext(CGSizeMake(60.0f, 60.0f));
[fullSizeImage drawInRect:CGRectMake(0,0,60.0f, 60.0f)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
you would probably want to only do this once for each image, and then cache the result.