1

I need to create a yuv image in NV21 format for testing purpose.

From this posting, Displaying YUV Image in Android, I see it does:

YuvImage yuvImage = new YuvImage(data, PictureFormat.NV21, width, height, null);

How can I get 'data'? to passing in yuvImage? Can I load it from a resource file, what should be the resource file format?

Community
  • 1
  • 1
michael
  • 106,540
  • 116
  • 246
  • 346

1 Answers1

1

You can get your desired Parameter (data) by Converting the resource Drawable to Bytearray then use it to get the YUV image :

Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.my_pic);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitMapData = stream.toByteArray();
ExceedLimits
  • 141
  • 3
  • is 'my_pic' a jpg? or what kind of file is it? Why I need to call" bitmap.compress()"? – michael Apr 06 '14 at 18:32
  • my_pic is a drawable image, Jpg or Png .. and you need to reference android.graphics.Bitmap in order to use "compress" method.. – ExceedLimits Apr 07 '14 at 11:40