如何在Android中将opengl纹理转换回位图? [英] How do you convert opengl texture back to bitmap in android?
本文介绍了如何在Android中将opengl纹理转换回位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I wanted to apply image-filter to my image and used android HelloEffects sample
它将图像数据从位图转换为纹理.
应用图像滤镜效果后,我想以jpeg格式恢复图像,但是不知道该怎么做.
It converts the image data from bitmap to texture.
After applying the image filter effect, I'd like to get the image back in jpeg format, but don't know how to do that.
推荐答案
我以类似的方式做到了这一点,
I did this in one way like ,
-
我使用glreadpixles()方法将纹理图像转换为位图
I converted the texture image into bitmap using glreadpixles() method
然后我将位图保存到sd卡
I then saved the bitmap to the sd card
纹理到位图代码
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, that OpenGL bitmap is incompatible with Android bitmap
//and so, some 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;
}
位图到内部存储代码,
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();
}
}
这篇关于如何在Android中将opengl纹理转换回位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文