1

I want to set Image in pdf.i use iText for set Image in pdf.I Succsessfully Diaplayed image From Assets folder.But I want To display Image from sd card path. following is code for display image from assets folder.

 try { InputStream ims = con.getAssets().open("prof_image.png"); Bitmap bmp = BitmapFactory.decodeStream(ims); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); Image image = Image.getInstance(stream.toByteArray()); image.setAlignment(Image.ALIGN_RIGHT); cell.addElement(image); //cell.setHorizontalAlignment(Element.ALIGN_CENTER); //alignment //cell.setBackgroundColor(new GrayColor(0.75f)); //cell background color cell.setFixedHeight(60); //cell height table.addCell(cell); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } 
2
  • what error message you are getting?? post your logcat here Commented Mar 21, 2018 at 11:15
  • i have not error,but i have not idea about how to display image from sd card Commented Mar 21, 2018 at 11:17

1 Answer 1

1
try { String photoPath = Environment.getExternalStorageDirectory()+"/gtu.png"; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bmp = BitmapFactory.decodeFile(photoPath, options); //InputStream ims = con.getAssets().open("prof_image.png"); //Bitmap bmp = BitmapFactory.decodeStream(ims); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); Image image = Image.getInstance(stream.toByteArray()); image.setAlignment(Image.ALIGN_RIGHT); cell.addElement(image); //cell.setHorizontalAlignment(Element.ALIGN_CENTER); //alignment //cell.setBackgroundColor(new GrayColor(0.75f)); //cell background color cell.setFixedHeight(60); //cell height table.addCell(cell); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.