当前位置: 首页>>代码示例>>Java>>正文


Java ImageReader.acquireLatestImage方法代码示例

本文整理汇总了Java中android.media.ImageReader.acquireLatestImage方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReader.acquireLatestImage方法的具体用法?Java ImageReader.acquireLatestImage怎么用?Java ImageReader.acquireLatestImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.ImageReader的用法示例。


在下文中一共展示了ImageReader.acquireLatestImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: imageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
/**
 * 图像可用时截屏
 *
 * @param reader
 * @param path
 *@param callback @return
 */
private void imageAvailable(ImageReader reader, String path, IRecordShotCallback callback) {
    mImageReaderLock.lock();
    try{
        Image image = reader.acquireLatestImage();

        if(image == null) return;
        int width = image.getWidth();
        int height = image.getHeight();
        final Image.Plane[] planes = image.getPlanes();
        final ByteBuffer buffer = planes[0].getBuffer();
        int pixelStride = planes[0].getPixelStride();
        int rowStride = planes[0].getRowStride();
        int rowPadding = rowStride - pixelStride * width;
        Bitmap bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888);
        bitmap.copyPixelsFromBuffer(buffer);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
        image.close();
        //需要在这里释放图片否则会截取很多图片
        release();

        saveBitmap(path, bitmap, callback);
    }finally {
        mImageReaderLock.unlock();
    }
}
 
开发者ID:sunshinecoast,项目名称:ScreenRecordCaptureMaster,代码行数:33,代码来源:CaptureScreenImage.java

示例2: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
        public void onImageAvailable(ImageReader reader) {
//            mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile, mImages));
            Image image = null;
            try {
                image = reader.acquireLatestImage();
                ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                byte[] bytes = new byte[buffer.capacity()];
                buffer.get(bytes);
                mImages.add(ByteString.copyFrom(bytes));
                showToast(String.valueOf(mImages.size()) + "/" + String.valueOf(mTotal), Toast.LENGTH_LONG);
                if(mImages.size() >= mTotal) {
                    showToast(String.valueOf("Calibrating..."), Toast.LENGTH_LONG);
                    final Activity activity = getActivity();
                    if (activity != null) {
                        activity.runOnUiThread(new GrpcPostImageRunnable());
                    }
                }

            } finally {
                if (image != null) {
                    image.close();
                }
            }
        }
 
开发者ID:TongLi1992,项目名称:Camera_Calibration_Android,代码行数:26,代码来源:Camera2BasicFragment.java

示例3: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    try (Image image = reader.acquireLatestImage()) {
        if (image == null) {
            throw new IllegalStateException();
        }

        if (image.getFormat() != ImageFormat.JPEG) {
            Log.e(TAG, "Unexpected image format: %d", image.getFormat());
            throw new IllegalStateException();
        }

        final byte[] capturedData = readCapturedData(image);
        nativeOnPhotoTaken(mNativeVideoCaptureDeviceAndroid, mCallbackId, capturedData);

    } catch (IllegalStateException ex) {
        notifyTakePhotoError(mCallbackId);
        return;
    }

    if (createPreviewObjectsAndStartPreview()) return;

    nativeOnError(mNativeVideoCaptureDeviceAndroid, "Error restarting preview");
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:25,代码来源:VideoCaptureCamera2.java

示例4: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    Image image = null;
    try {
        image = reader.acquireLatestImage();
        ByteBuffer buffer = image.getPlanes()[0].getBuffer();
        byte[] imageBytes = new byte[buffer.remaining()];
        buffer.get(imageBytes);
        Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
        final String text = runModel(bitmap);
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                textView.setText(text);

            }
        });
    } finally {
        if (image != null) {
            image.close();
        }
    }
}
 
开发者ID:neural-nuts,项目名称:Cam2Caption,代码行数:24,代码来源:Camera2BasicFragment.java

示例5: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    Image image = reader.acquireLatestImage();
    // get image bytes
    ByteBuffer imageBuf = image.getPlanes()[0].getBuffer();
    final byte[] imageBytes = new byte[imageBuf.remaining()];
    imageBuf.get(imageBytes);
    image.close();

    onPictureTaken(imageBytes);
}
 
开发者ID:androidthings,项目名称:doorbell,代码行数:12,代码来源:DoorbellActivity.java

示例6: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    Image image = reader.acquireLatestImage();
    try {
        if (image.getFormat() == ImageFormat.JPEG) {
            ByteBuffer buffer = image.getPlanes()[0].getBuffer();
            byte[] data = new byte[buffer.remaining()];
            buffer.get(data);
            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

            WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
            int rotation = windowManager.getDefaultDisplay().getRotation();
            Bitmap rotated = ImageUtils.rotateBitmap(bitmap, rotation, mCamera2Engine.getSensorOrientation());
            mImageView.setImageBitmap(rotated);
        }
    } finally {
        image.close();
    }
}
 
开发者ID:cattaka,项目名称:AndroidSnippets,代码行数:20,代码来源:CameraApi2ExampleActivity.java

示例7: GetBitmapFromImageReader

import android.media.ImageReader; //导入方法依赖的package包/类
/**
 * Retrieve Bitmap with specific format from ImageReader.
 *
 * @param imageReader the image reader
 * @return bitmap
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static Bitmap GetBitmapFromImageReader(ImageReader imageReader) {
    Bitmap bitmap;

    //get image buffer
    Image image = imageReader.acquireLatestImage();
    final Image.Plane[] planes = image.getPlanes();
    final ByteBuffer buffer = planes[0].getBuffer();

    int pixelStride = planes[0].getPixelStride();
    int rowStride = planes[0].getRowStride();
    int rowPadding = rowStride - pixelStride * image.getWidth();
    // create bitmap
    bitmap = Bitmap.createBitmap(image.getWidth() + rowPadding / pixelStride, image.getHeight(), Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(buffer);
    image.close();
    return bitmap;
}
 
开发者ID:tranquvis,项目名称:SimpleSmsRemote,代码行数:25,代码来源:ImageUtils.java

示例8: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
	Image image = reader.acquireLatestImage();

	if (image != null) {
		ByteBuffer buffer = image.getPlanes()[0].getBuffer();

		if (rgbaData == null) {
			rgbaData = new byte[width * height * 4];
		}

		buffer.get(rgbaData);

		videoStreamingConnection.sendVideoFrame(rgbaData);

		image.close();
	}
}
 
开发者ID:holtaf,项目名称:youtube_livestream,代码行数:19,代码来源:StreamerActivity.java

示例9: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    Image image;
    synchronized (this) {
        ++imageAvailable;
        if (imageAvailable != 2) {
            image = reader.acquireLatestImage();
            if (image == null) return;
            image.close();
            return;
        }
    }
    image = reader.acquireLatestImage();
    if (image == null) return;
    final Image.Plane[] planes = image.getPlanes();
    final Buffer buffer = planes[0].getBuffer().rewind();
    int pixelStride = planes[0].getPixelStride();
    int rowStride = planes[0].getRowStride();
    int rowPadding = rowStride - pixelStride * width;
    // create bitmap
    Bitmap bitmap = Bitmap.createBitmap(width+rowPadding/pixelStride, height, Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(buffer);
    tearDown();
    image.close();

    cb.onScreenshot(bitmap);
}
 
开发者ID:hailongren,项目名称:android-screen-shot,代码行数:28,代码来源:Screenshotter.java

示例10: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader imageReader) {
    Log.d("MainActivity", "onImageAvailable");
    final Image image = imageReader.acquireLatestImage();
    count++;
    if (count == 100) {
        byte[] yuv = new byte[image.getWidth() * image.getHeight() * 3 / 2];
        image2yuv(image, yuv);
        saveRawYuvData(yuv, image.getWidth(), image.getHeight(), "org");
    }
    image.close();
}
 
开发者ID:Piasy,项目名称:AndroidPlayground,代码行数:13,代码来源:MainActivity.java

示例11: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    Image image = reader.acquireLatestImage();
    ByteBuffer buffer = image.getPlanes()[0].getBuffer();
    byte[] imageData = new byte[buffer.remaining()];
    buffer.get(imageData);

    saveImage(imageData);
    image.close();
}
 
开发者ID:team-supercharge,项目名称:SCCameraView,代码行数:11,代码来源:Camera2View.java

示例12: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    //Log.i(TAG, "onImageAvailable");
    Image img = reader.acquireLatestImage();
    if (img != null) {
        processImage(img);
        img.close();
    }
}
 
开发者ID:galme,项目名称:ROLF-EV3,代码行数:10,代码来源:PCVideoStreamer.java

示例13: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
    try {
        final Image image = reader.acquireLatestImage();
        if (image != null) {
            mCameraFrameCallback.onFrameData(image, image::close);
        }
    } catch (OutOfMemoryError | IllegalStateException e) {
        CameraCompat.onError(CameraCompat.ERR_UNKNOWN);
    }
}
 
开发者ID:Piasy,项目名称:CameraCompat,代码行数:12,代码来源:Camera2PreviewCallback.java

示例14: acquireJpegBytesAndClose

import android.media.ImageReader; //导入方法依赖的package包/类
/**
 * Given an image reader, extracts the JPEG image bytes and then closes the
 * reader.
 *
 * @param reader the reader to read the JPEG data from.
 * @return The bytes of the JPEG image. Newly allocated.
 */
private static byte[] acquireJpegBytesAndClose(ImageReader reader) {
    Image img = reader.acquireLatestImage();

    ByteBuffer buffer;

    if (img.getFormat() == ImageFormat.JPEG) {
        Image.Plane plane0 = img.getPlanes()[0];
        buffer = plane0.getBuffer();
    } else if (img.getFormat() == ImageFormat.YUV_420_888) {
        buffer = ByteBuffer.allocateDirect(img.getWidth() * img.getHeight() * 3);

        Log.v(TAG, "Compressing JPEG with software encoder.");
        int numBytes = JpegUtilNative.compressJpegFromYUV420Image(img, buffer, JPEG_QUALITY);

        if (numBytes < 0) {
            throw new RuntimeException("Error compressing jpeg.");
        }

        buffer.limit(numBytes);
    } else {
        throw new RuntimeException("Unsupported image format.");
    }

    byte[] imageBytes = new byte[buffer.remaining()];
    buffer.get(imageBytes);
    buffer.rewind();
    img.close();
    return imageBytes;
}
 
开发者ID:jameliu,项目名称:Camera2,代码行数:37,代码来源:OneCameraImpl.java

示例15: onImageAvailable

import android.media.ImageReader; //导入方法依赖的package包/类
@Override
        public void onImageAvailable(ImageReader reader) {
//            mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));
            final Image image = reader.acquireLatestImage();
            if (image == null) return;
            try {
                executor.execute(new Runnable() {
                    @Override
                    public void run() {
                        final String result = BarCodeTaskWorker.runDecode(image);
                        image.close();
                        if (result != null) {
                            Handler mainHandler = new Handler(Looper.getMainLooper());

                            Runnable myRunnable = new Runnable() {
                                @Override
                                public void run() {
                                    onDecodeResult(result);
                                }
                            };
                            mainHandler.post(myRunnable);
                        }
                    }
                });
            } catch (RejectedExecutionException e) {
                image.close();
            }

//            reader.acquireLatestImage().close();

        }
 
开发者ID:katiesandford,项目名称:parkscan,代码行数:32,代码来源:CameraPreviewActivityFragment.java


注:本文中的android.media.ImageReader.acquireLatestImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。