0

MediaProjection クラスで画像をキャプチャするためのテスト アプリケーションを作成しました。

imageReader = ImageReader.newInstance(currentWidth, currentHeight, PixelFormat.RGBA_8888, 2);
imageReader.setOnImageAvailableListener(this, null);

virtualDisplay = mediaProjection.createVirtualDisplay("captureDisplay",
                    currentWidth, currentHeight,  DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY |
                            DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC| 
                            DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR |
                            DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE |
                          DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION, Screen.getDensity(mContext),                          imageReader.getSurface(), null, null);

// DisplayManager フラグは軌跡のみです

そしてonImageAvailable(ImageReader reader)方法で

次のように画像を取得しようとしました:

Bitmap bitmap;

Image mImage = null;

try {

mImage = mImageReader .acquireLatestImage();

if (img != null) {

    final Image.Plane[] planes = mImage.getPlanes();

    final ByteBuffer buffer = planes[0].getBuffer();

    int pixelStride = planes[0].getPixelStride();

    int rowStride = planes[0].getRowStride();

    int rowPadding = rowStride - pixelStride * mImage.getWidth();

    bitmap = Bitmap.createBitmap(mImage.getWidth() + rowPadding/pixelStride, mImage.getHeight(), Bitmap.Config.ARGB_8888);  

    bitmap.copyPixelsFromBuffer(buffer);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

   byte[] rawData = lastImageAcquiredRaw = stream.toByteArray();

   if (rawData != null) {

    Bitmap fullScreen = BitmapFactory.decodeByteArray(rawData, 0, rawData.length);

    savebitmap(fullScreen,"image",i); //Saving bitmap in storage

    }

}

今までは問題なく、アプリが横向きのときに正しい画像を取得しています。直面している問題は向きの変更にあります。適切な画像が得られません。ランドスケープに戻すと、適切にキャプチャされないこともあります。

ImageReader.java クラスを通過しました。向きの変更を処理する必要があるなど、何も言及されていません。

acquireNextImageNoThrowISE()、acquireNextImage() を使用しようとしましたが、使用しませんでした。

オリエンテーションで適切な画像を取得しようとした、または可能性がある人はいますか?

適切なイメージを得るために私を助けてください。

4

1 に答える 1