pdf generation - After Conversion of GLsurfaceview (bitmap) to pdf file , some other colors in the image is missing, in android Opengles2.0 -
i developing autocad app desktop in android using opengl es2.0 . drawn objects in glsurfaceview,like lines, cirles, , linear dimensioning etc. after drawn objects on glsurfaceview. capture screen of glsurfaceview , make pdf file conversion. then, open pdf file, objects misssing....
this output first-image : original output , second-image : pdf file output...
my code:
note: in code, when click button, take screenshot image , save in sdcard location. used boolean condition in ondraw method if condition, why because, renderer class, ondraw method calling anytime, anyway, code executed without boolean condition, saved lots of images in memory card, that's why put boolean condition.
mainactivity class :
protected boolean printoptionenable = false; saveimagebutton.setonclicklistener( new onclicklistener() { @override public void onclick(view v) { log.v("hari", "pan button clicked"); issaveclick = true; myrenderer.printoptionenable = issaveclick; } } );
myrenderer class :
int width_surface , height_surface ; @override public void onsurfacechanged(gl10 gl, int width, int height) { log.i("jo", "onsurfacechanged"); // adjust viewport based on geometry changes, // such screen rotation gles20.glviewport(0, 0, width, height); float ratio = (float) width / height; width_surface = width ; height_surface = height ; } //--------------------------------------------------------------------- @override public void ondrawframe(gl10 gl) { try { if ( printoptionenable ) { printoptionenable = false ; log.i("hari", "printoptionenable if condition:"+printoptionenable); int w = width_surface ; int h = height_surface ; log.i("hari", "w:"+w+"-----h:"+h); int b[]=new int[(int) (w*h)]; int bt[]=new int[(int) (w*h)]; intbuffer buffer=intbuffer.wrap(b); buffer.position(0); gles20.glreadpixels(0, 0, w, h,gles20.gl_rgba,gles20.gl_unsigned_byte, buffer); for(int i=0; i<h; i++) { //remember, opengl bitmap incompatible android bitmap //and so, correction need. for(int j=0; j<w; j++) { int pix=b[i*w+j]; int pb=(pix>>16)&0xff; int pr=(pix<<16)&0x00ff0000; int pix1=(pix&0xff00ff00) | pr | pb; bt[(h-i-1)*w+j]=pix1; } } bitmap inbitmap = null ; if ( inbitmap == null || !inbitmap.ismutable() || inbitmap.getwidth() != w || inbitmap.getheight() != h) { inbitmap = bitmap.createbitmap(w, h, bitmap.config.argb_8888); } //bitmap.createbitmap(w, h, bitmap.config.argb_8888); inbitmap.copypixelsfrombuffer(buffer); //return inbitmap ; // return bitmap.createbitmap(bt, w, h, bitmap.config.argb_8888); inbitmap = bitmap.createbitmap(bt, w, h, bitmap.config.argb_8888); bytearrayoutputstream bos = new bytearrayoutputstream(); inbitmap.compress(compressformat.jpeg, 90, bos); byte[] bitmapdata = bos.tobytearray(); bytearrayinputstream fis = new bytearrayinputstream(bitmapdata); final calendar c=calendar.getinstance(); long mytimestamp=c.gettimeinmillis(); string timestamp=string.valueof(mytimestamp); string myfile="hari"+timestamp+".jpeg"; dir_image=new file(environment.getexternalstoragedirectory()+file.separator+ "printerscreenshots"+file.separator+"image"); dir_image.mkdirs(); try { file tmpfile = new file(dir_image,myfile); fileoutputstream fos = new fileoutputstream(tmpfile); byte[] buf = new byte[1024]; int len; while ((len = fis.read(buf)) > 0) { fos.write(buf, 0, len); } fis.close(); fos.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } log.v("hari", "screenshots:"+dir_image.tostring()); } } catch(exception e) { e.printstacktrace() ; } }
please 1 me..
thanks advance
Comments
Post a Comment