0

I want to save a view's snapshot to a file, but comes the error. My code is as following:

View decor = ***; //

int width = decor.getWidth();
int height = decor.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

Canvas canvas = new Canvas(bitmap);
decor.draw(canvas);

int bytes = bitmap.getByteCount() + 8;
ByteBuffer buffer = ByteBuffer.allocate(bytes);
buffer.putInt(width);
buffer.putInt(height);
bitmap.copyPixelsToBuffer(buffer);
byte[] array = buffer.array();

but bitmap.copyPixelsToBuffer(buffer); will crash.

the error is like this:

12-09 08:36:43.107: E/libEGL(14642): call to OpenGL ES API with no current context (logged once per thread)

This error only happens on Android 5.0, are there any changes in the new platform? I know android 5.0 use a ThreadedRender to render a surface, how can I handle this problem? Thanks very much!!!

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47

1 Answers1

0

Even i am facing the same problem! It seems like in pre-lollipop version the context was leaking and is being used by default (I assume). But with lollipop it is strictly needed to create or pass the context explicitly!

hope these helps! https://stackoverflow.com/a/27092070

Community
  • 1
  • 1