在Android程序开发过程中,明确哪些图像格式类(ImageFormat、PixelFormat及BitmapConfig等)及图像(JPG、PNG及BMP等)的转换方式非常重要,在以后的程序开发过程中会起到非常重要的作用。在一个项目开发过程中一款软件的开发和图像处理有着密切的关系,特别是在移动应用程序,在视觉效果等方面起到至关重要的作用,因为这关系到用户体验度。下面通过代码实例给大家分享下:
关于图像格式类,介绍以下三个:ImageFormat、PixelFormat及BitmapConfig。
1、ImageFormat(android.graphics.ImageFormat),格式参数有以下几种:
int JPEG ,Encoded formats,常量值: 256 (0x00000100)
int NV16,YCbCr format, used for video,16 (0x00000010)
int NV21,YCrCb format used for images, which uses the NV21 encoding format,常量值: 17 (0x00000011)
int RGB_565,RGB format used for pictures encoded as RGB_565,常量值: 4 (0x00000004)
int UNKNOWN, 常量值:0 (0x00000000)
int YUY2,YCbCr format used for images,which uses YUYV (YUY2) encoding format,20 (0x00000014)
int YV12,Android YUV format,This format is exposed to software decoders and applications
YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed by (W/2) x (H/2) Cr and Cb planes
解释总是英文的最通俗易懂,这里就不献丑翻译了。用法举例,在构建ImageReader类的对象时,会用到ImageFormat类的图像格式对象。如
ImageReader imageReader = ImageReader.newInstance(width, height, ImageFormat.RGB_565, 2);
imageReader对象表示其缓存中最多存在宽高分别为width和height、RGB_565格式的图像流两帧。
在需求中用哪一种图像格式,要视实际情况而定,后面