How do you convert opengl texture back to bitmap in android? -
i wanted apply image-filter image , used android helloeffects sample
it converts image data bitmap texture.
after applying image filter effect, i'd image in jpeg format, don't know how that.
i did in 1 way ,
i converted texture image bitmap using glreadpixles() method
i saved bitmap sd card
texture bitmap code
public static bitmap savepixels(int x, int y, int w, int h){ int b[]=new int[w*(y+h)]; int bt[]=new int[w*h]; intbuffer ib = intbuffer.wrap(b); ib.position(0); gles20.glreadpixels(0, 0, w, h, gles20.gl_rgba, gles20.gl_unsigned_byte, ib); for(int i=0, k=0; i<h; i++, k++) {//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-k-1)*w+j]=pix1; } } bitmap sb=bitmap.createbitmap(bt, w, h, bitmap.config.argb_8888); return sb; }
bitmap internal storage code,
public static void saveimage(bitmap finalbitmap) { file mydir=new file("/sdcard/saved_images"); mydir.mkdirs(); random generator = new random(); int n = 10000; n = generator.nextint(n); string fname = "image-"+ n +".jpg"; file file = new file (mydir, fname); if (file.exists ()) file.delete (); try { fileoutputstream out = new fileoutputstream(file); finalbitmap.compress(bitmap.compressformat.jpeg, 90, out); out.flush(); out.close(); } catch (exception e) { e.printstacktrace(); } }
Comments
Post a Comment