[IOS] Pit daddy's Alasset (Assets Library Framework)

Source: Internet
Author: User

Assets Library Framework can be used to do the multi-selector on iOS, choose Photo Video What is not introduced.

The current project is a bit like Dropbox, where you can choose photos from your device and then upload your files, using the assets Library Framework, in the background.

Alasset can be seen as a wrapper class for the file you choose, from which you can take an object called Alassetpresentation (defaultrepresentation), and then, if it is a picture, you can get full-screen, full-size drawings, metadata, size, etc. useful information.

The problem arises: when the user modifies the photo save using the Iphone/ipad built-in Photos app, the assets Library framework selection is used to see the modified thumbnail OK The full screen image (Fullscreenimage) inside the defaultpresentation is also the modified OK; Full-size drawing (fullresolutionimage) is an unmodified diagram, asset gives the file URL if you upload directly, most of the picture software Open will show the original! (At least our project docking server side generated to our thumbnail image is the original thumbnail, download this map directly with ImageView look is also the original), Pit Daddy!

Go back to the Photos app to open this image into the editing state can see a button lit, called "Revert to Original", point a piece to restore.

The principle is photos to the image processing, and does not really save a new picture, but will be processed through a property called "ADJUSTMENTXMP" into the original image of the metadata.

How can this be good? After studying the following solutions, I hope to be helpful to those who do not know:

1. Judging asset is a picture

2. Take the Defaultrepresentation (hereinafter referred to as Rep) in asset

3. Take the "ADJUSTMENTXMP" of metadata in rep (hereinafter referred to as adj)

4. If there is a adj, turn adj into a group of Cifilter

5. Take the original Fullresolutionimage (hereinafter referred to as IMG)

6. Using Cifilter one-by-one "Processing" IMG, the final generation is the desired image

7. Do whatever want ... For example, our project is to save the generated image as a temporary file and upload it.

The sample code is as follows (asset is the Alasset object returned by the assets Library framework):

1 //work with photos modified images from iOS2     if([[[Asset Valueforproperty:alassetpropertytype] Isequaltostring:alassettypephoto]) {3Alassetrepresentation *rep =[Asset defaultrepresentation];4NSString *adj = [Rep metadata][@"ADJUSTMENTXMP"];5         if(adj) {6Cgimageref Fullresimage =[Rep fullresolutionimage];7NSData *xmldata =[adj datausingencoding:nsutf8stringencoding];8Ciimage *image =[Ciimage imagewithcgimage:fullresimage];9Nserror *error =Nil;TenNsarray *filters =[Cifilter filterarrayfromserializedxmp:xmldata One inputimageextent:[image Extent] Aerror:&ERROR]; -Cicontext *context =[Cicontext Contextwithoptions:nil]; -             if(Filters &&!)error) { the                  for(Cifilter *filterinchfilters) { - [Filter Setvalue:image Forkey:kciinputimagekey]; -Image =[Filter outputimage]; -                 } +Fullresimage =[Context Createcgimage:image fromrect:[image extent]; -UIImage *result =[UIImage imagewithcgimage:fullresimage + Scale:[rep Scale] A Orientation: (uiimageorientation) [Rep orientation]]; at                 //Do whatever your want with the result image then. -             } -         } -}

Finally, at the same time, in the study of this problem, in small ah Apple's official website Assets Library Framework Reference found the following paragraph:

IMPORTANT

In IOS 8.0 and later, use the Photos framework instead of the Assets Library framework. The Photos framework provides more features and better performance for working with a user ' s photo library. See Photos Framework Reference

Thx for reading!

[IOS] Pit daddy's Alasset (Assets Library Framework)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.