對於一個應用程序,我試圖用我公司的所有同事解析一個vcf文件。其中一些人沒有真正的照片,而是自動地插入一張虛擬照片。現在爲了使應用程序具備未來的可用性,我不想檢查現在可以工作的500x500的分辨率。負責生成vcf的部門的想法是爲他們總是使用的虛擬照片庫文件添加評論。我想讀書,在斯威夫特,但沒有運氣,你可以在我的測試操場代碼中看到:從png文件中讀取(自定義)EXIF數據
import UIKit
import ImageIO
let photo = UIImage(named: "bild")!
let photoData = UIImagePNGRepresentation(photo)!
let base64String = photoData.base64EncodedString()
let photoSource = CGImageSourceCreateWithData(photoData as CFData, nil)!
for (key, value) in CGImageSourceCopyPropertiesAtIndex(photoSource, 0, nil) as! [String : Any] {
print("\(key): \(value)")
}
輸出:
PixelWidth: 500
Depth: 8
ProfileName: sRGB IEC61966-2.1
HasAlpha: 1
ColorModel: RGB
{PNG}: {
Chromaticities = (
"0.3127",
"0.329",
"0.64",
"0.33",
"0.3",
"0.6000000000000001",
"0.15",
"0.06"
);
Gamma = "0.45455";
InterlaceType = 0;
sRGBIntent = 0;
}
PixelHeight: 500
的exiftool
在終端的輸出同時顯示了這個在同一圖像上(特別參見User Comment
和Document Name
(自定義字段):
➔ exiftool bild.png
ExifTool Version Number : 10.50
File Name : bild.png
Directory : .
File Size : 4.2 kB
File Modification Date/Time : 2017:05:06 12:51:23+02:00
File Access Date/Time : 2017:05:06 12:51:24+02:00
File Inode Change Date/Time : 2017:05:06 12:51:23+02:00
File Permissions : rw-r--r--
File Type : PNG
File Type Extension : png
MIME Type : image/png
Image Width : 500
Image Height : 500
Bit Depth : 8
Color Type : Palette
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
Palette : (Binary data 477 bytes, use -b option to extract)
Transparency : 0
Background Color : 0
Pixels Per Unit X : 2835
Pixels Per Unit Y : 2835
Pixel Units : meters
Modify Date : 2017:05:05 08:04:36
Exif Byte Order : Big-endian (Motorola, MM)
Document Name : dummy
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Y Cb Cr Positioning : Centered
Exif Version : 0231
Components Configuration : Y, Cb, Cr, -
User Comment : dummy
Flashpix Version : 0100
Color Space : Uncalibrated
Image Size : 500x500
Megapixels : 0.250
我已經嘗試過通過使用kCGImagePropertyExifU訪問用戶評論serComment,但它返回零,我想這將只返回一定的價值,如果上面的代碼也和預期一樣:
let userComment = dict[kCGImagePropertyExifUserComment as String] // User Comment is set --> but this returns nil
let pixelWidth = dict[kCGImagePropertyPixelWidth as String] // As a reference that this does normally work --> shows 500 as expected
你有什麼建議,如何添加評論是可讀與圖像SWIFT代碼?
PNGs不包含EXIF。 PNG格式有它自己的元數據塊,exiftool可以讀取,但'CoreImage'不一定。但是通過'libpng'讀取它們並不難。 –
好吧,這解釋了爲什麼我無法閱讀它們,但是如何在iOS應用程序中導入'libpng'來獲取iPhone上的元數據? –
椰子樹怎麼樣? https://cocoapods.org/pods/libpng –