Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

UIImagePickerController's editInfo>CropRect inaccurate

Hey gang,

I've been working through this issue for a while, and all searches, resources are thin. Perhaps one of you might have the answer.

I'm using a UIImagePickerController with allowsImageEditing = YES. Everything except one thing works fine. I can take the image from the photo library and resize the edited image to a rect that is 160 pixels larger then the image given. The editInfo gives you an image of size 320 x 320 be default, and ergo a cropping rect of 320 x 320, or smaller depending if they zoomed in. Then I alter the image rect. I do some stuff so it keeps the same scaling but adds the extra height, giving my final picture output the size of 320 x 480.

The problem is when I use the following sourceType for my picker: UIImagePickerControllerSourceTypePhotoLibrary. It allows me to pick an image from the 'camera roll'. This is fine, but once I pick a picture from the 'camera roll' the cropping rect it gives me is 432 x 433 (provided no zooming was done). The image size is still 320 x 480 (as all my images in the bin are).

So, to sum it up. Could anyone explain why the editInfo in my didFinishPicking method gives me a croppingRect of something larger than 320x320, even when the image it gives me is 320x320?

I must be missing something simple for this unless it's a problem in the API?

If I am missing any information about anything, or you just feel you need more information, please just post here and I will respond.

Thanks in advance for any help/suggestions.


I'll post my method that shows how I alter the image. The code is not mine and has been posted around the internet for a while. This is the one method that handles it.


- (UIImage*)scaleImage:(UIImage*)anImage withEditingInfo:(NSDictionary*)editInfo
{
UIImage *newImage;

UIImage *originalImage = [editInfo valueForKey:@\"UIImagePickerControllerOriginalImage\"];
CGSize originalSize = CGSizeMake(originalImage.size.width, originalImage.size.height);
CGRect originalFrame;
originalFrame.origin = CGPointMake(0,0);
originalFrame.size = originalSize;

CGRect croppingRect = [[editInfo valueForKey:@\"UIImagePickerControllerCropRect\"] CGRectValue];
CGSize croppingRectSize = CGSizeMake(croppingRect.size.width, croppingRect.size.height);

CGSize croppedScaledImageSize = anImage.size;

float scaledBarClipHeight = 80;

CGSize scaledImageSize;
float scale;

if(!CGSizeEqualToSize(croppedScaledImageSize, originalSize)){

scale = croppedScaledImageSize.width/croppingRectSize.width;
float barClipHeight = scaledBarClipHeight/scale;

croppingRect.origin.y -= barClipHeight;
croppingRect.size.height += (2*barClipHeight);

if(croppingRect.origin.y<=0)
{

croppingRect.size.height += croppingRect.origin.y;
croppingRect.origin.y=0;
}

if(croppingRect.size.height > (originalSize.height - croppingRect.origin.y))
{
croppingRect.size.height = (originalSize.height - croppingRect.origin.y);
}


scaledImageSize = croppingRect.size;
scaledImageSize.width *= scale;
scaledImageSize.height *= scale;


NSLog(@\"croppingRect = (%f, %f)<>(%f, %f)\", croppingRect.origin.x, croppingRect.origin.y, croppingRect.size.width, croppingRect.size.height);
NSLog(@\"scaledImageSize = (%f, %f)\", scaledImageSize.width, scaledImageSize.height);

newImage = [self cropImage:originalImage to:croppingRect andScaleTo:scaledImageSize];

}else{

newImage = originalImage;

}

return newImage;
}
Post edited by Legrend on

Replies

  • nagarajannagarajan Posts: 124Registered Users
    Hello Experts,

    Please help me for getting a single image from photo library!!!

    Thanks,
    Nagarajan T.
  • LegrendLegrend Posts: 22Registered Users
    nagarajan;79215 said:
    Hello Experts,

    Please help me for getting a single image from photo library!!!

    Thanks,
    Nagarajan T.

    That's awfully rude of you, unnecessary, and plain stupid. Read carefully, and take more time to comprehend before you post something that is not in ANYWAY helpful and misleading to others.

    I will try to explain the issue I am having again. I am retrieving pictures from the bin and from the camera roll correctly. I can even set my pictures if needed. The problem lies within the "editInfo" that is sent as a parameter to the didFinishingPicking: editInfo: method.

    The editInfo (to my understanding and research) shows that if you use the "allowsImageEditing = YES" feature for the picker, the image you RECEIVE in the didFinishPicking: method will be 320 x 320 in size, and the CGRect given from the editInfo parameter will be a 320 x 320 rect for a scale of 1.0 or down to a 107 x 107 rect for a scale of ~3.0.

    This data has been confirmed for the bin. However, when editing a picture for the camera roll, the picture size is still 320 x 320 with no scaling, but the CGRect given to me as the area the picture was taken from is 432 x 433. My picture isn't even that large. The screen isn't even that large.

    Why am I receiving a larger CGRect as a parameter for the picture when:
    A) the picture is only 320x 480,
    B) the screen is only 320 x 480,
    and C) the image I receive was not zoomed when editing and is of size 320 x 320?
  • nagarajannagarajan Posts: 124Registered Users
    Legrend;79373 said:
    That's awfully rude of you, unnecessary, and plain stupid. Read carefully, and take more time to comprehend before you post something that is not in ANYWAY helpful and misleading to others.

    I will try to explain the issue I am having again. I am retrieving pictures from the bin and from the camera roll correctly. I can even set my pictures if needed. The problem lies within the "editInfo" that is sent as a parameter to the didFinishingPicking: editInfo: method.

    The editInfo (to my understanding and research) shows that if you use the "allowsImageEditing = YES" feature for the picker, the image you RECEIVE in the didFinishPicking: method will be 320 x 320 in size, and the CGRect given from the editInfo parameter will be a 320 x 320 rect for a scale of 1.0 or down to a 107 x 107 rect for a scale of ~3.0.

    This data has been confirmed for the bin. However, when editing a picture for the camera roll, the picture size is still 320 x 320 with no scaling, but the CGRect given to me as the area the picture was taken from is 432 x 433. My picture isn't even that large. The screen isn't even that large.

    Why am I receiving a larger CGRect as a parameter for the picture when:
    A) the picture is only 320x 480,
    B) the screen is only 320 x 480,
    and C) the image I receive was not zoomed when editing and is of size 320 x 320?
    Great thanks...

    Regards,
    Nagarajan T
  • bunnyherobunnyhero Posts: 1New Users
    Have you found a solution to this? I've run into the same frustrating issue. The cropping rect info is useless because the coordinate system it uses is unpredictable. After some experimentation, it seems that JPEGs that are close in size to 320x480 will trigger this odd behaviour. Larger images are more predictable: they give you a cropping rectangle as though the original image was 640 pixels wide.
Sign In or Register to comment.