android - Getting Image from drawable and adding to PDF using iText -


i want add image android pdf using itext. want achieve without saving image sdcard first. put image res/drawable folder proving image path doesn’t work , throws filenotfound exception. path this:

string path = “res/drawable/myimage.png” image image = image.getinstance(path); document.add(image); 

now please suggest me solution how add correct file path getinstance(…) method. thanks

of course it'll not work @ way.

move image assets folder access getassets() method

// load image     try {             // input stream            inputstream ims = getassets().open("myimage.png");            bitmap bmp = bitmapfactory.decodestream(ims);            bytearrayoutputstream stream = new bytearrayoutputstream();            bmp.compress(bitmap.compressformat.png, 100, stream);            image image = image.getinstance(stream.tobytearray());            document.add(image);         }    catch(ioexception ex)         {             return;         } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -