Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Photos framework checking image type

I have code for fetching the photos from the library and accessing the types. But i have no idea how to check whether the image is PNG or JPEG.? by ALAssetLibrary we can do this easily. I want to implement this by Photos framework. Anyone have any idea.? Any suggestions. Thanks in advance.

like image 559
Alvin Varghese Avatar asked Dec 02 '14 06:12

Alvin Varghese


People also ask

How do I know the type of an image?

If you are having trouble and want to check if you photo is a JPEG, look at the writing under the photo in its file name. If it ends . jpg or . jpeg- then the file is a JPEG and will upload.

How do you tell if an image is actually a PNG?

Open a file in a Hex editor (or just a binary file viewer). PNG files start with 'PNG', . jpg files should have 'exif'or 'JFIF' somewhere in the beginning.

How do I know if Iphone is JPEG or PNG?

Start by navigating to the location of the document, video, or image, and then perform a Haptic Touch gesture (long-press) on the item. On the menu that pops up, tap Info. You can then see the file format listed next to the file name.

What is Phasset?

A representation of an image, video, or Live Photo in the Photos library.


1 Answers

Try:

let asset: PHAsset = ...
let opts = PHImageRequestOptions()
// opts.synchronous = true // If you want synchronous callback
opts.version = PHImageRequestOptionsVersion.Original
PHImageManager.defaultManager().requestImageDataForAsset(asset, options: opts) { _, uti, _, _ in
    println(uti)
}

I don't know how to do this without fetching actual data.


To convert UTI to MIME-Type:

import MobileCoreServices

let uti = ...
let mime = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType).takeRetainedValue()
like image 139
rintaro Avatar answered Sep 22 '22 19:09

rintaro