As we know apple has introduce new image called "Live Photo". Live photo looks like very shore video. Here my question is how can we get each frame or images form Live photo so that we can make other opration on this images like editing,sharing etc.
PHLivePhoto has a UIImage *image property
edit: and an AVAsset * videoAsset for the video
If you pick the live photo using UIImagePicker, you can get one single image like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
Related
In my app I'm having two imageviews, first imageview will be constant and for second imageview ,after picking image it will zoom and it can be place any where in the view and second image will be merged with first image and after merging second imageview will be nil and first imageview will be having two images and we can pic as many images in second imageview and can move anywhere but we need pic only single image at single time.How to implement this.?.Thanks in advance.
A simple image usually has 32bit of color information per pixel (rgb: ff ff ff), a grayscale image has 8bit.
It should be obvious that a conversion from 32bit to 8bit is not reversible.
To achieve your goal you have to keep a copy of your original Image.
When you select Image from gallery save it in one UIImage object as original image before applying any grayscale on that.
Make another copy of selected Image and apply grayscale on that and assign this image to ImageView.
Now when you touch on this ImageView (Detect touch using Gestures) set originalImage to the ImageView.
Edit:
You can have function like this:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
// Edited image works great (if you allowed editing)
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
}
In above code you can declare both editedImage and originalImage variables at global scope, assign editedImage as image for your ImageView and on touch on ImageView you can show originalImage
I'm trying to upload UIImage which taken from UIImagePickerController using UIImageJPEGRepresentation. But it shows on server with wrong orientation. First of all, I'd like to ask is there way to fix it on my side? Or if not how to handle it on server?
I already saw iOS 4 Image Oriented Incorrectly When Posted To Server and this one Save UIImage, Load it in Wrong Orientation but I need to show image with right orientation directly on server not in application.
From what I've found, this seems to be the best answer.
iOS UIImagePickerController result image orientation after upload
Add the category UIImage+fixOrientation to your project and import "UIImage+fixOrientation.h" in your view controller.
Then you should be able to use something like this.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
image = [image fixOrientation];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
}
try
UIImage *orientationFixedImage = [UIImage imageWithCGImage:[originalImage CGImage] scale:1.0 orientation:originalImage.imageOrientation];
When I chose a portrait photo from the library like that :
(source: hostingpics.net)
The UIImage returned by the library is rotated.
Here is my code :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
UIImage* originalImg = [editInfo objectForKey:UIImagePickerControllerOriginalImage];
[self useImage:originalImg];
}
How can I avoid that ?
self.imageData=[info objectForKey:#"UIImagePickerControllerOriginalImage"];
CIImage *image = [[CIImage alloc] initWithImage:[info objectForKey:#"UIImagePickerControllerOriginalImage"]];
self.imageData=[UIImage imageWithCIImage:image scale:self.imageData.scale orientation:self.imageData.imageOrientation];
You can use the below methods to retain the image's orientation:
[UIImage imageWithCIImage:(CIImage *) scale:(CGFloat) orientation:(UIImageOrientation)];
[UIImage imageWithCGImage:(CGImageRef) scale:(CGFloat) orientation:(UIImageOrientation)];
Did you previously take the image using an image picker in your app and then save the image?
If so, did you set the orientation when you saved the image? You need to.
Consider adding a log statement or debugging to check what orientation is set on the image.
If the orientation is set on the image then UIImageView will automatically render the image correctly.
If (in the future) you're going to take the image data and upload it somewhere then you would need to check the orientation and re-draw the image while applying an appropriate transform to the context.
I am working on an application for iPad, it is working fine until i reached this point:
The app shows the popover for the photo library, but when I choose the photo, the popover doesn't hide, and I also want it to view the selected image in a UIImageView, however i do not know how.
I am sure there is something wrong in the didFinishpickingMediaWithInfo function. here is the function's code:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishpickingMediaWithInfo:(NSDictionary *)info{
//bgImage is a UIImageView
bgImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Dismiss UIImagePickerController and release it [picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
[picker release];
}
My first question is: What am I supposed to add to this function for viewing the selected photo in the UIImageView? (When I click on the photo from the photo library in the simulator, neither the photo library hide nor the image is viewed in the specified UIImageView)
2- I have read that I should've used UIImage instead of UIImageView.. Is this true? If yes, what about the interface builder? There is nothing called UIImage?
To close the image picker, use:
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
What you get from
bgImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
is not an UIImageView, it's a UIImage. To get it displayed, you need to have a UIImageView in your UI somewhere, and set the view's image with what you just got from the picker:
imageView.image = bgImage
Hope this helps
How to get Image size in Objective-C.
I loaded one image using imagePicker, I want know the size of that image. (w*h)
is it possible?
Thanks & regards...
You implement the UIImagePickerControllerDelegate Protocol and in particular the imagePickerController:didFinishPickingMediaWithInfo: method. The last parameter in that method is a dictionary that includes an UImage references by the UIImagePickerControllerOriginalImage key. Get this UIImage* and get it's size property.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];
//access width and height like this
image.size.width;
image.size.height;
}