// 保存GL绘制的图形 public static Bitmap saveGLBitmap(int width_surface, int height_surface) { // isSave = false; 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++) { /** * 由于OpenGL与Android的Bitmap不兼容,这里需要进行一些校正 */ 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.PNG, 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"; File dir_image = new File(Environment.getExternalStorageDirectory() + File.separator + "printerscreenshots"); dir_image.mkdirs(); try { File tmpFile = new File(dir_image + "/" + System.currentTimeMillis() + ".png"); 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(); } return inBitmap; }
public static Bitmap combineBitmap(Bitmap background, Bitmap foreground) { if (background == null) { return null; } int bgWidth = background.getWidth(); int bgHeight = background.getHeight(); int fgWidth = foreground.getWidth(); int fgHeight = foreground.getHeight(); Bitmap newmap = Bitmap .createBitmap(bgWidth, bgHeight, Config.ARGB_8888); Canvas canvas = new Canvas(newmap); canvas.drawBitmap(background, 0, 0, null); canvas.drawBitmap(foreground, (bgWidth - fgWidth) / 2, (bgHeight - fgHeight) / 2, null); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); return newmap; }
拍摄AR场景技术实现(有关键源码),布布扣,bubuko.com
原文:http://blog.csdn.net/ggtaas/article/details/25104665