通过IText的API增加Raw图像时,Raw图像是字节对齐的,我程序里面加的是2值的Raw图像
Image img = Image.getInstance(156, 1024, 1, 1, imgBytes);
其中的imgBytes是字节对齐的Raw图像,我原本以为imgBytes的长度为156*1304/8=25428就可以了,但是测试的时候一直报ArraysIndexOutOfBoundsException.然后我把imgBytes的长度改为Math.ceil(156/8f)*8*1304/8=160*1304/8=26080就OK了,此测试证明调用
Image.getInstance(int width,int height,int components,int bpc,byte[] data)
时Raw图像是字节对齐的.
getInstance
public static Image getInstance (int width, int height, int components, int bpc, byte[] data) throws BadElementException
-
Gets an instance of an Image in raw mode.
-
-
Parameters:
-
width
- the width of the image in pixels -
height
- the height of the image in pixels -
components
- 1,3 or 4 for GrayScale, RGB and CMYK -
data
- the image data -
bpc
- bits per component
Returns:
-
an object of type
ImgRaw
Throws:
-
BadElementException
- on error
-