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


Java Image.close方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:sunshinecoast,项目名称:ScreenRecordCaptureMaster,代码行数:33,代码来源:CaptureScreenImage.java

示例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();
                }
            }
        }
 
开发者ID:TongLi1992,项目名称:Camera_Calibration_Android,代码行数:26,代码来源:Camera2BasicFragment.java

示例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);
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:22,代码来源:HostDeviceScreenCast.java

示例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();
        }
    }
}
 
开发者ID:neural-nuts,项目名称:Cam2Caption,代码行数:24,代码来源:Camera2BasicFragment.java

示例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;
}
 
开发者ID:googlecodelabs,项目名称:androidthings-imageclassifier,代码行数:23,代码来源:ImagePreprocessor.java

示例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;
}
 
开发者ID:androidthings,项目名称:sample-tensorflow-imageclassifier,代码行数:23,代码来源:ImagePreprocessor.java

示例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;
}
 
开发者ID:Deeplocal,项目名称:android-things-drawbot,代码行数:23,代码来源:ImagePreprocessor.java

示例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);
}
 
开发者ID:androidthings,项目名称:doorbell,代码行数:12,代码来源:DoorbellActivity.java

示例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();
    }
}
 
开发者ID:cattaka,项目名称:AndroidSnippets,代码行数:20,代码来源:CameraApi2ExampleActivity.java

示例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;
}
 
开发者ID:tranquvis,项目名称:SimpleSmsRemote,代码行数:25,代码来源:ImageUtils.java

示例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();
	}
}
 
开发者ID:holtaf,项目名称:youtube_livestream,代码行数:19,代码来源:StreamerActivity.java

示例12: tryClose

import android.media.Image; //导入方法依赖的package包/类
private void tryClose(Image image) {
    try {
        image.close();
    } catch (Exception ignored) {

    }
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:8,代码来源:ScreenCapturer.java

示例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;
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:28,代码来源:CaptureHelper.java

示例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();
            }
        }
    }
}
 
开发者ID:yohhoy,项目名称:heifreader,代码行数:28,代码来源:HeifReader.java

示例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();
            }
        }
}
 
开发者ID:opentok,项目名称:accelerator-core-android,代码行数:38,代码来源:ScreenSharingCapturer.java


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