IOS photo operation (getting information and modifying photos)

  • 2021-07-22 11:36:25
  • OfStack

IOS Photo Action (Getting Information and Modifying Photos)

Recently, the customer wants a photo watermark, and modifies other contents including obtaining location, and modifying events, etc. Oh, yes, I remembered the method of changing uiview to UIimage. Yes


<span style="font-size:14px;">- (UIImage*)convertViewToImage:(UIView*)v 
{ 
  CGSize s = v.bounds.size; 
  UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale); 
   
  CGContextRef context = UIGraphicsGetCurrentContext(); 
   
  [v.layer renderInContext:context]; 
   
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
  UIGraphicsEndImageContext(); 
   
  v.layer.contents = nil; 
  return image; 
   
}</span><span style="font-size:12px;"> 
</span> 

However, the added content is the time of the photo and the status of GPS, which is slightly private

Hum, I thought of the callback in UIImagePickerController, which can take photos or take them out of the photo album

< span style="font-size:14px;" > - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { < /span >

< span style="font-size:14px;" > //info There are big articles in it < /span >

< span style="font-size:14px;" > } < /span >

ok first looks at the photo, and the photo info contains three parameters


<span style="font-size:14px;">UIImagePickerControllerMediaMetadata  // Detailed data, everything  exif Right  
UIImagePickerControllerMediaType    // Type, jpg,png Of this kind  
UIImagePickerControllerOriginalImage  // Dimensions </span> 

The data we need is just found in info [UIImagePickerControllerMediaMetadata]. Thief details of time or something

The next one is taken out from the photo album, and the info taken out from the photo album is also three, but the

UIImagePickerControllerMediaMetadata is replaced by UIImagePickerControllerReferenceURL. See url's father, address.

IOS8 comes out with a new photo gallery < Photos/Photos.h >

I don't need the ass before, and I won't use it either

< span style="font-size:14px;" > PHAsset *asset = [PHAsset fetchAssetsWithALAssetURLs:@[assetURL] options:nil][0]; < /span >

That's it? Well, the information is all in asset. The information inside is quite complete, just take it directly.

Notice that sometimes we need addresses that happen to have addresses in them
@property (nonatomic,strong, readonly,nullable) CLLocation *location;

This is it. With latitude and longitude, we have to restore the address. At first, I thought it was the Earth coordinates, but I didn't expect it to be the Mars coordinates in line with our socialist core values.

Kui I also find a way to convert, this is directly put in and wait for the callback address can be

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: