私は、MediaProjectionクラスで画像をキャプチャするためのテストアプリケーションを作成しました。オリエンテーションを変更してMediaProjectionで画像キャプチャを処理する方法は?
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
}
}
今、私はOKだと私はティル:
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)
方法
に、私は次のように画像を取得しようとしましたトレイルです私のアプリが横向きのときに正しいImageを取得する。直面している問題は向きが変わっている、私は適切な画像を取得していない。景色に戻って再び適切にキャプチャしていない時に再び何度か。
私はImageReader.javaクラスを使いました。オリエンテーションの変更を処理する必要性について何も言及していません。
acquireNextImageNoThrowISE()、acquireNextImage()を使用してみましたが、使用しませんでした。
オリエンテーションで正しい画像を取得しようとしたことがありますか?
適切な画像を取得するのに手伝ってください。
よろしく
「canDetectOrientation」とは何ですか? – 1234567
完全なコードを共有できますか?https://github.com/mtsahakis/MediaProjectionDemo – mtsahakis