如何保存位图从GLSurfaceView(仅限位图,而不是整机的质感) [英] How to save bitmap from GLSurfaceView (Only bitmap, not whole texture)

查看:837
本文介绍了如何保存位图从GLSurfaceView(仅限位图,而不是整机的质感)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这$ C $下把位图是对GlSurfaceView多效。 应用效果,对图像,使用效果

I am using this code to give multiple effect on bitmap that is on GlSurfaceView. apply-effects-on-image-using-effects

现在,我要保存的位图。他们已经给了code键保存位图,但是与,整个GlSurfaceView将被保存为位图图像。相反,我想只保存位图区域保存为图片。

Now, I want to save the bitmap. They have given the code to save the bitmap but with that, whole GlSurfaceView is going to be saved as bitmap image. Instead I want to save only bitmap area to save as Image.

有方法,它的像素和,使位图,也使图像。 例如:

There is method that takes pixels and make bitmap from that and also make image. e.g.:

  public Bitmap takeScreenshot(GL10 mGL) {
  final int mWidth = mEffectView.getWidth();
  final int mHeight = mEffectView.getHeight();
  IntBuffer ib = IntBuffer.allocate(mWidth * mHeight);
  IntBuffer ibt = IntBuffer.allocate(mWidth * mHeight);


  mGL.glReadPixels(0, 0, mWidth, mHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);

   // Convert upside down mirror-reversed image to right-side up normal
  // image.
  for (int i = 0; i < mHeight; i++) {
   for (int j = 0; j < mWidth; j++) {
    ibt.put((mHeight - i - 1) * mWidth + j, ib.get(i * mWidth + j));
   }
  }

   Bitmap mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
  mBitmap.copyPixelsFromBuffer(ibt);
  return mBitmap;
 }

我想,我需要更新它喜欢,相反,它是从0开始,0,应该开始使用位图左上角的坐标。这应该工作到位图的高度和宽度。

I guess, I need to update it like, instead it to be start with 0, 0, that should be start with bitmap top left coordinate. And that should work till bitmap height and width.

所以,与我能解决我的问题,但不知道怎么弄的位图图像GLSurfaceView的坐标。

So, with that I can able to resolved my issue but don't know how to get that coordinate of bitmap image in GLSurfaceView.

请检查下面的图片更多的澄清。

Please check below image for more clarification.

原始图片:

输入图像的描述在这里

在影响屏幕的加载图像:

输入图像的描述在这里

图片应用效果后,并将其保存:

输入图像的描述在这里

这就是我想要的。

输入图像的描述在这里

推荐答案

如果你能得到的图像的尺寸,就可以得到位图的准确位置。

If you can get the dimensions of the image, you can get the exact position of the bitmap.

让图像尺寸为 X ,并获得了屏幕尺寸下的这个帖子。那一定是 A B

Let the image dimensions be x and y, and get the screen dimensions following this post. Let that be a and b.

您的首发位置将是((AX)/ 2,(通过)/ 2)

使用此裁剪图像。

这篇关于如何保存位图从GLSurfaceView(仅限位图,而不是整机的质感)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆