gpt4 book ai didi

android - 如何从 GLSurfaceView 保存位图(仅位图,不是整个纹理)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:15 24 4
gpt4 key购买 nike

我正在使用这段代码对 GlSurfaceView 上的位图产生多重效果。 apply-effects-on-image-using-effects

现在,我想保存位图。他们已经给出了保存位图的代码,但是有了这个,整个 GlSurfaceView 将被保存为位图图像。相反,我只想保存位图区域以另存为图像。

有一种方法可以获取像素并从中制作位图,也可以制作图像。例如:

  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,应该从位图左上角坐标开始。这应该适用于位图高度和宽度。

因此,我可以解决我的问题,但不知道如何在 GLSurfaceView 中获取位图图像的坐标。

请查看下图以获得更多说明。

原始图片:

enter image description here

在效果画面中加载图片:

enter image description here

应用效果并保存后的图像:

enter image description here

这就是我想要的。

enter image description here

最佳答案

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

设图像尺寸为xy,得到屏幕尺寸如下this post .让它成为 ab

您的起始位置将是 ((a-x)/2, (b-y)/2)

使用它裁剪您的图像。

关于android - 如何从 GLSurfaceView 保存位图(仅位图,不是整个纹理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32601187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com