In my app, user can select a pic from album or camera where i can get uiimage representation. Since the album may have pic from web, the file type is not only jpg. Then i need to sent it to the server without convertion. Here i can only use nsdata.
I know UIImageJPEGRepresentation and UIImagePNGRepresentation, but i think this two method may convert the original image. Maybe when quality set to 1 UIImageJPEGRepresentation can get original pic?
Is there any method to get the original uiimage nsdata?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
You can use the
ALAssetsLibrary
andALAssetRepresentation
to get the original data. Example:But there are some things to consider:
assetForURL:
works asynchronously.assetForURL:
will cause a confirmation dialog, which might be irritating the user:assetForURL:
calls the failure block.assetForURL:
will fail without asking the user again. Only if you reset the location warnings in System Settings, the user is asked again.So you should be prepared that this method fails and use
UIImageJPEGRepresentation
orUIImagePNGRepresentation
as a fallback. But in that case you will not get the original data, e.g. the metadata (EXIF etc.) are missing.On iOS 8.0+ use PHImageManager.default().requestImageData() after you locate the corresponding asset in the assets (you can get to assets with PHAsset.fetchAssets().
See more info and example code in my answer to very similar question How to upload image that was taken from UIImagePickerController.