目前,用户在片段中选择他们的图像,并将它们转换为带有字符串路径名的数组。我想将该图像放在 PDF 上,但存在格式问题。我正在尝试使用下面的代码来解决这个问题。目前一切检查通过,直到 cursor.MoveToFirst() 返回 null。for (int i = 0; i <= imgArray.size(); i++) { Uri selectedImageUri = Uri.fromFile(new File(imgArray.get(i))); String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(selectedImageUri, filePathColumn, null, null, null); cursor.moveToFirst(); //ERROR: NULL int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); Bitmap bmp = BitmapFactory.decodeFile(picturePath); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); Image image = Image.getInstance(stream.toByteArray()); doc.add(image); }
1 回答

泛舟湖上清波郎朗
TA贡献1818条经验 获得超3个赞
解决方案:我想出了这个。这似乎对我有用!使用位图配置。
for (int i = 0; i < imgArray.size(); i++) {
Bitmap bmp = BitmapFactory.decodeFile(imgArray.get(i));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image image = Image.getInstance(stream.toByteArray());
doc.add(image);
}
添加回答
举报
0/150
提交
取消