为了账号安全,请及时绑定邮箱和手机立即绑定

Android Studio (java):使用 iText 从数组到 PDF 的图像

Android Studio (java):使用 iText 从数组到 PDF 的图像

皈依舞 2021-12-30 20:35:54
目前,用户在片段中选择他们的图像,并将它们转换为带有字符串路径名的数组。我想将该图像放在 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);



        }


查看完整回答
反对 回复 2021-12-30
  • 1 回答
  • 0 关注
  • 189 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号