2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GLSurfaceViewメモ

Last updated at Posted at 2019-04-09

GLSurfaceViewのサイズ変更

LayoutParamsでサイズ指定してGLSurfaceView.setLayoutParams()で設定

.java
public class MainActivity extends Activity {

    private GLSurfaceView mGLView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mGLView = new GLSurfaceView(this);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(800,400);
        mGLView.setLayoutParams(params);
        setContentView(mGLView);
        
        ...

GLSurfaceViewの保存

GLSurfaceView.Rendererの継承クラスに新しくメソッドを作り、その中で別スレッド立てて行う

.java
int pixels[] = new int[width * height];
IntBuffer buffer = IntBuffer.wrap(pixels);
buffer.position(0);

GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);

try {
    FileOutputStream fos = null;
    fos = new FileOutputStream(new File(DOWNLOAD + "/tmp.png"));
    bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
    fos.close();
    Log.d("Plug-in", "save: " + DOWNLOAD + "/tmp.png");
}catch (IOException ex) {
    Log.d("Plug-in", ex.toString());
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?