亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號