) 앱의 경우 회사의 모든 동료와 vcf-File을 구문 분석하려고합니다. 그들 중 일부는 실제 사진이없고 자동으로 더미 사진이 삽입됩니다. 이제 앱이 미래의 증거가 될 수 있도록 지금 당장 작동 할 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
당신이 방법에 읽을 수있는 이미지에 주석을 추가하는 제안이 있습니까 신속한 코드?
PNG에는 EXIF가 포함되어 있지 않습니다. PNG 형식에는 'exiftool'이 읽을 수있는 자체 메타 데이터 청크가 있지만 'CoreImage'는 읽을 필요가 없습니다. 그러나'libpng'를 통해 그것들을 읽는 것은 그렇게 어렵지 않습니다. –
좋아요, 왜 그걸 읽을 수 없는지 설명하지만 아이폰 OS 앱에서'libpng'을 가져 와서 아이폰에서 메타 데이터에 접근 할 수있는 방법은 뭔가요? –
코코아포드는 어때요? https://cocoapods.org/pods/libpng –