本文整理汇总了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();
}
}
示例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();
}
}
}
示例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");
}
示例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();
}
}
}
示例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);
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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();
}