本文整理汇总了Java中android.media.Image.close方法的典型用法代码示例。如果您正苦于以下问题:Java Image.close方法的具体用法?Java Image.close怎么用?Java Image.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.Image
的用法示例。
在下文中一共展示了Image.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: imageAvailable
import android.media.Image; //导入方法依赖的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.Image; //导入方法依赖的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: decodeToBitmap
import android.media.Image; //导入方法依赖的package包/类
private Bitmap decodeToBitmap(final Image img) {
Image.Plane[] planes = img.getPlanes();
if (planes[0].getBuffer() == null) {
return null;
}
int width = img.getWidth();
int height = img.getHeight();
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(planes[0].getBuffer());
img.close();
return Bitmap.createBitmap(bitmap, 0, 0, width, height, null, true);
}
示例4: onImageAvailable
import android.media.Image; //导入方法依赖的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: preprocessImage
import android.media.Image; //导入方法依赖的package包/类
public Bitmap preprocessImage(final Image image) {
if (image == null) {
return null;
}
Assert.assertEquals("Invalid size width", rgbFrameBitmap.getWidth(), image.getWidth());
Assert.assertEquals("Invalid size height", rgbFrameBitmap.getHeight(), image.getHeight());
if (croppedBitmap != null && rgbFrameBitmap != null) {
ByteBuffer bb = image.getPlanes()[0].getBuffer();
rgbFrameBitmap = BitmapFactory.decodeStream(new ByteBufferBackedInputStream(bb));
Helper.cropAndRescaleBitmap(rgbFrameBitmap, croppedBitmap, 0);
}
image.close();
// For debugging
if (SAVE_PREVIEW_BITMAP) {
Helper.saveBitmap(croppedBitmap);
}
return croppedBitmap;
}
示例6: preprocessImage
import android.media.Image; //导入方法依赖的package包/类
public Bitmap preprocessImage(final Image image) {
if (image == null) {
return null;
}
Assert.assertEquals("Invalid size width", rgbFrameBitmap.getWidth(), image.getWidth());
Assert.assertEquals("Invalid size height", rgbFrameBitmap.getHeight(), image.getHeight());
if (croppedBitmap != null && rgbFrameBitmap != null) {
ByteBuffer bb = image.getPlanes()[0].getBuffer();
rgbFrameBitmap = BitmapFactory.decodeStream(new ByteBufferBackedInputStream(bb));
Helper.cropAndRescaleBitmap(rgbFrameBitmap, croppedBitmap, 0);
}
image.close();
// For debugging
if (SAVE_PREVIEW_BITMAP) {
Helper.saveBitmap(croppedBitmap);
}
return croppedBitmap;
}
示例7: preprocessImage
import android.media.Image; //导入方法依赖的package包/类
public Bitmap preprocessImage(final Image image) {
if (image == null) {
return null;
}
Assert.assertEquals("Invalid size width", rgbFrameBitmap.getWidth(), image.getWidth());
Assert.assertEquals("Invalid size height", rgbFrameBitmap.getHeight(), image.getHeight());
if (croppedBitmap != null && rgbFrameBitmap != null) {
ByteBuffer bb = image.getPlanes()[0].getBuffer();
rgbFrameBitmap = BitmapFactory.decodeStream(new ByteBufferBackedInputStream(bb));
Helper.cropAndRescaleBitmap(rgbFrameBitmap, croppedBitmap, 0);
}
image.close();
// For debugging
if (SAVE_PREVIEW_BITMAP) {
Helper.saveBitmap(mContext, croppedBitmap);
}
return croppedBitmap;
}
示例8: onImageAvailable
import android.media.Image; //导入方法依赖的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);
}
示例9: onImageAvailable
import android.media.Image; //导入方法依赖的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();
}
}
示例10: GetBitmapFromImageReader
import android.media.Image; //导入方法依赖的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;
}
示例11: onImageAvailable
import android.media.Image; //导入方法依赖的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();
}
}
示例12: tryClose
import android.media.Image; //导入方法依赖的package包/类
private void tryClose(Image image) {
try {
image.close();
} catch (Exception ignored) {
}
}
示例13: screenShot
import android.media.Image; //导入方法依赖的package包/类
public Bitmap screenShot() {
log.d("screenShot " + imageReader);
Image image = imageReader.acquireLatestImage(); //获取缓冲区中的图像,关键代码
if (image == null)
return null;
boolean b = true;
if (b) {
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();
return bitmap;
}
return null;
}
示例14: renderHevcImageWithFormat
import android.media.Image; //导入方法依赖的package包/类
private static Bitmap renderHevcImageWithFormat(ByteBuffer bitstream, ImageInfo info, int imageFormat) throws FormatFallbackException {
try (ImageReader reader = ImageReader.newInstance(info.size.getWidth(), info.size.getHeight(), imageFormat, 1)) {
renderHevcImage(bitstream, info, reader.getSurface());
Image image = null;
try {
try {
image = reader.acquireNextImage();
} catch (UnsupportedOperationException ex) {
throw new FormatFallbackException(ex);
}
switch (image.getFormat()) {
case ImageFormat.YUV_420_888:
case ImageFormat.YV12:
return convertYuv420ToBitmap(image);
case ImageFormat.RGB_565:
return convertRgb565ToBitmap(image);
default:
throw new RuntimeException("unsupported image format(" + image.getFormat() + ")");
}
} finally {
if (image != null) {
image.close();
}
}
}
}
示例15: onImageAvailable
import android.media.Image; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader) {
Image mImage = null;
FileOutputStream fos = null;
try {
mImage = mImageReader.acquireLatestImage();
if (mImage != null) {
int imgWidth = mImage.getWidth();
int imgHeight = mImage.getHeight();
Image.Plane[] planes = mImage.getPlanes();
ByteBuffer buffer = planes[0].getBuffer();
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * imgWidth;
Buffer buffer2 = planes[0].getBuffer().rewind();
bmp = Bitmap.createBitmap(imgWidth + rowPadding / pixelStride, imgHeight, Bitmap.Config.ARGB_8888);
bmp.copyPixelsFromBuffer(buffer2);
lastBmp = bmp.copy(bmp.getConfig(), true);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bmp != null) {
bmp.recycle();
}
if (mImage != null) {
mImage.close();
}
}
}