iOSiOS学习iOS 开发每天分享优质文章

翻译 官方 ImageIO(一)

2016-11-13  本文已影响148人  学习路上一个远行者

使用ImageIO的基础

ImageIO 框架提供了不透明数据类型来对图片数据进行读取从一个(CGImageSourceRef)和把一个image数据写到目标(CGImageDestionationRef)。它支持广泛的图像类型,包括标准的网络图片、高动态图、相机原始数据。ImageIO框架有其他的功能例如:

在你的应用中使用ImageIO框架

导入ImageIO 框架,之后再代码文件中引入头文件 #import <ImageIO/ImageIO.h>

支持的图片格式
ImageIO框架支持大多常用的图片格式:JPEG /JPEG2000 RAW TIFF BMP PNG .每个平台支持的格式都不一样。如果你想要获取最新的ImageIO支持的图片文件类型,你可以调用这些方法:

代码1-1生成和打印支持的UTIs

    CFArrayRef mySourceTypes = CGImageSourceCopyTypeIdentifiers();
    CFShow(mySourceTypes);
    CFArrayRef myDestinationTypes = CGImageDestinationCopyTypeIdentifiers();
    CFShow(myDestinationTypes);

输出结果:

(
    "public.jpeg",
    "public.png",
    "com.compuserve.gif",
    "com.canon.tif-raw-image",
    "com.adobe.raw-image",
    "com.dxo.raw-image",
    "com.canon.cr2-raw-image",
    "com.leafamerica.raw-image",
    "com.hasselblad.fff-raw-image",
    "com.hasselblad.3fr-raw-image",
    "com.nikon.raw-image",
    "com.nikon.nrw-raw-image",
    "com.pentax.raw-image",
    "com.samsung.raw-image",
    "com.sony.raw-image",
    "com.sony.sr2-raw-image",
    "com.sony.arw-raw-image",
    "com.epson.raw-image",
    "com.kodak.raw-image",
    "public.tiff",
    "com.canon.crw-raw-image",
    "com.fuji.raw-image",
    "com.panasonic.raw-image",
    "com.panasonic.rw2-raw-image",
    "com.leica.raw-image",
    "com.leica.rwl-raw-image",
    "com.konicaminolta.raw-image",
    "com.olympus.sr-raw-image",
    "com.olympus.or-raw-image",
    "com.olympus.raw-image",
    "public.jpeg-2000",
    "com.microsoft.ico",
    "com.microsoft.bmp",
    "com.adobe.photoshop-image",
    "com.microsoft.cur",
    "com.truevision.tga-image",
    "com.ilm.openexr-image",
    "public.radiance",
    "public.mpo-image",
    "public.pbm",
    "public.pvr",
    "org.khronos.astc",
    "org.khronos.ktx",
    "com.microsoft.dds",
    "com.apple.rjpeg"
)
(
    "public.jpeg",
    "public.png",
    "com.compuserve.gif",
    "public.tiff",
    "public.jpeg-2000",
    "com.microsoft.ico",
    "com.microsoft.bmp",
    "com.adobe.photoshop-image",
    "com.adobe.pdf",
    "com.truevision.tga-image",
    "com.ilm.openexr-image",
    "public.pbm",
    "public.pvr",
    "org.khronos.astc",
    "org.khronos.ktx",
    "com.microsoft.dds",
    "com.apple.rjpeg"
)

通过打印出来的结果发现source image 支持的图像类型要比destination image 支持的图像类型多

表格1-1UTIs的常量

唯一类型标识 图片类型常量
public.image kUTTypeImage
public.png kUTTypePNG
public.jpeg kUTTypeJPEG
public.jpeg-2000(OS ) kUTTypeJPEG2000
public.tiff kUTTypeTIFF
com.apple.pict(OS) kUTTypePICT
com.compuserve.gif kUTTypeGIF
上一篇下一篇

猜你喜欢

热点阅读