I develop the app that take screenshot of other apps.
when I develop it using android device the code below works.
mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 5);
but the code doesn't work in android app player for pc (momo app player) because the PixelFormat.RGBA_8888 isn't right for momo app player.
so I changed PixelFormat.RGBA_8888 to PixelFormat.RGBX_8888
althought the code works properly, the code below doesn't work because pixelformat is changed.
Image img = null;
try {
int format = reader.getImageFormat();
Log.v(TAG, "format" + format);
img = reader.acquireLatestImage();
if (img != null) {
Image.Plane[] planes = img.getPlanes();
if (planes[0].getBuffer() == null) {
return;
}
int width = img.getWidth();
int height = img.getHeight();
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * width;
byte[] newData = new byte[width * height * 4];
int offset = 0;
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
//bitmap = Bitmap.createBitmap(bitmap1, mCheckWidthMin, mCheckHeightMin, mGapWidth, mGapHeight);
ByteBuffer buffer = planes[0].getBuffer();
for (int i = 0; i < width; ++i) {
for (int j = 0; j < height; ++j) {
int pixel = 0;
pixel |= (buffer.get(offset) & 0xff) << 16; // R
pixel |= (buffer.get(offset + 1) & 0xff) << 8; // G
pixel |= (buffer.get(offset + 2) & 0xff); // B
pixel |= (buffer.get(offset + 3) & 0xff) << 24; // A
bitmap.setPixel(j, i, pixel);
offset += pixelStride;
//else Log.v(TAG, "Attacking");
//if ( i <= mCheckWidthMax && i >= mCheckWidthMin && j >= mCheckHeightMin && j <= mCheckHeightMax) {
if ( i <= 171 && i >= 164 && j >= 236 && j <= 241) {
if(!isAttacked){
checkAttack(pixel, i, j);
}
}
//if ( i == 169 && j == 240) checkAttack(pixel, i, j);
}
offset += rowPadding;
}
I think The simple way to make it work is changing image format from RGBX to RGBA.
is there any way to change pixelformat?
or how can I get RGB value from PixelFormat.RGBX_8888?
please help and save my time.
thank you!