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


Java Image.getWidth方法代码示例

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


在下文中一共展示了Image.getWidth方法的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: 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

示例3: extract

import android.media.Image; //导入方法依赖的package包/类
/**
 * Extracts the Y-Plane from the YUV_420_8888 image to creates a IntensityPlane.
 * The actual plane data will be copied into the new IntensityPlane object.
 *
 * @throws IllegalArgumentException if the provided images is not in the YUV_420_888 format
 */
@NonNull
public static IntensityPlane extract(@NonNull Image img) {
    if (img.getFormat() != ImageFormat.YUV_420_888) {
        throw new IllegalArgumentException("image format must be YUV_420_888");
    }

    Image.Plane[] planes = img.getPlanes();

    ByteBuffer buffer = planes[0].getBuffer();
    byte[] yPlane = new byte[buffer.remaining()];
    buffer.get(yPlane);

    int yRowStride = planes[0].getRowStride();

    return new IntensityPlane(img.getWidth(), img.getHeight(), yPlane, yRowStride);
}
 
开发者ID:BioID-GmbH,项目名称:BWS-Android,代码行数:23,代码来源:IntensityPlane.java

示例4: yuvToBgr

import android.media.Image; //导入方法依赖的package包/类
public static Mat yuvToBgr(Image image, Mat yuvMat) {
    Mat bgrMat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC4);
    //Log.d("TESTCALL", bgrMat.rows() + " " + bgrMat.cols());
    Imgproc.cvtColor(yuvMat, bgrMat, Imgproc.COLOR_YUV2BGR_I420);
    //Log.d("TESTCALL", yuvMat.rows() + " " + yuvMat.cols());
    return bgrMat;
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:8,代码来源:ImageUtil.java

示例5: onFrameData

import android.media.Image; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onFrameData(final Image image, final Runnable postProcessedTask) {
    final int width = image.getWidth();
    final int height = image.getHeight();
    if (mGLRgbaBuffer == null) {
        mGLRgbaBuffer = ByteBuffer.allocateDirect(width * height * 4);
    }
    if (mGLYuvBuffer == null) {
        // 16 bytes alignment
        int bufHeight = (width * mGLRender.getFrameWidth() / mGLRender.getFrameHeight())
                        & 0xfffffff0;
        mGLYuvBuffer = ByteBuffer.allocateDirect(width * bufHeight * 3 / 2);
    }
    if (!mGLRender.isBusyDrawing()) {
        RgbYuvConverter.image2rgba(image, mGLRgbaBuffer.array());
        mGLRender.scheduleDrawFrame(mGLRgbaBuffer, width, height, () -> {
            if (!mGLRender.isEnableFilter() && !mGLRender.isPaused()) {
                sendNormalImage(image);
            }
            postProcessedTask.run();
        });
    } else {
        postProcessedTask.run();
    }
}
 
开发者ID:Piasy,项目名称:CameraCompat,代码行数:27,代码来源:GPUImageChain.java

示例6: 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

示例7: _onSingleBarcode

import android.media.Image; //导入方法依赖的package包/类
private void _onSingleBarcode(String barcode, Point[] points, final Image source, final BarcodeDetectedListener listener, Handler callbackHandler) {
    if (listener != null) {
        final BarcodeInfo bc = new BarcodeInfo(barcode, points);
        final byte[] serialized = (source == null) ? null : ImageDecoder.Serialize(source);
        final int width = (source == null) ? 0 : source.getWidth();
        final int height = (source == null) ? 0 : source.getHeight();
        final int format = (source == null) ? ImageFormat.UNKNOWN : source.getFormat();
        callbackHandler.post(
                new Runnable() {
                    @Override
                    public void run() {
                        listener.onSingleBarcodeAvailable(bc, serialized, format, width, height);
                    }
                }
        );
    }
}
 
开发者ID:tschaumburg,项目名称:FastBarcodeScanner,代码行数:18,代码来源:FastBarcodeScanner.java

示例8: _onMultipleBarcodes

import android.media.Image; //导入方法依赖的package包/类
private void _onMultipleBarcodes(final Barcode[] barcodes, final Image source, final MultipleBarcodesDetectedListener listener, Handler callbackHandler) {
    if (listener != null) {
        final byte[] serialized = (source == null) ? null : ImageDecoder.Serialize(source);
        final int width = (source == null) ? 0 : source.getWidth();
        final int height = (source == null) ? 0 : source.getHeight();
        final int format = (source == null) ? ImageFormat.UNKNOWN : source.getFormat();
        callbackHandler.post(
                new Runnable() {
                    @Override
                    public void run() {
                        listener.onMultipleBarcodeAvailable(_convert(barcodes), serialized, format, width, height);
                    }
                }
        );
    }
}
 
开发者ID:tschaumburg,项目名称:FastBarcodeScanner,代码行数:17,代码来源:FastBarcodeScanner.java

示例9: SequentialIterator

import android.media.Image; //导入方法依赖的package包/类
public SequentialIterator(Image image, Rect area, boolean duplicateBuffer) {
    super(image, area, duplicateBuffer);
    Image.Plane plane = image.getPlanes()[0];
    int pixelStride = plane.getPixelStride();
    mRowStride = plane.getRowStride();
    mWidth = area.width();
    mHeight = area.height();
    int rowPadding = mRowStride - pixelStride * image.getWidth();
    mSkipPerRow = rowPadding + (image.getWidth() - mWidth) * pixelStride;
    int offset = mIterateArea.top * mRowStride + mIterateArea.left * pixelStride;
    mByteBuffer.position(offset);
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:13,代码来源:ColorIterator.java

示例10: ConcurrentImageColorIterator

import android.media.Image; //导入方法依赖的package包/类
public ConcurrentImageColorIterator(Image image, Rect area) {
    Image.Plane plane = image.getPlanes()[0];
    mByteBuffer = plane.getBuffer();
    mImageWidth = image.getWidth();
    mImageHeight = image.getHeight();
    mIterateArea = area;
    mAreaWidth = area.width();
    mAreaHeight = area.height();
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:10,代码来源:ConcurrentColorIterator.java

示例11: toBitmap

import android.media.Image; //导入方法依赖的package包/类
public static Bitmap toBitmap(Image image) {
    Image.Plane plane = image.getPlanes()[0];
    ByteBuffer buffer = plane.getBuffer();
    buffer.position(0);
    int pixelStride = plane.getPixelStride();
    int rowPadding = plane.getRowStride() - pixelStride * image.getWidth();
    Bitmap bitmap = Bitmap.createBitmap(image.getWidth() + rowPadding / pixelStride, image.getHeight(), Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(buffer);
    return bitmap;
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:11,代码来源:Images.java

示例12: pixel

import android.media.Image; //导入方法依赖的package包/类
public static int pixel(Image image, int x, int y) {
    int originX = x;
    int originY = y;
    ScreenMetrics metrics = new ScreenMetrics(image.getWidth(), image.getHeight());
    x = metrics.rescaleX(x);
    y = metrics.rescaleY(y);
    Image.Plane plane = image.getPlanes()[0];
    int offset = y * plane.getRowStride() + x * plane.getPixelStride();
    int c = plane.getBuffer().getInt(offset);
    Log.d("Images", String.format(Locale.getDefault(), "(%d, %d)→(%d, %d)", originX, originY, x, y));
    return (c & 0xff000000) + ((c & 0xff) << 16) + (c & 0x00ff00) + ((c & 0xff0000) >> 16);
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:13,代码来源:Images.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: convertYuv420ToBitmap

import android.media.Image; //导入方法依赖的package包/类
private static Bitmap convertYuv420ToBitmap(Image image) {
    RenderScript rs = mRenderScript;
    final int width = image.getWidth();
    final int height = image.getHeight();

    // prepare input Allocation for RenderScript
    Type.Builder inType = new Type.Builder(rs, Element.U8(rs)).setX(width).setY(height).setYuvFormat(ImageFormat.YV12);
    Allocation inAlloc = Allocation.createTyped(rs, inType.create(), Allocation.USAGE_SCRIPT);
    byte[] rawBuffer = new byte[inAlloc.getBytesSize()];
    int lumaSize = width * height;
    int chromaSize = (width / 2) * (height / 2);
    Image.Plane[] planes = image.getPlanes();
    planes[0].getBuffer().get(rawBuffer, 0, lumaSize);
    planes[1].getBuffer().get(rawBuffer, lumaSize, chromaSize);
    planes[2].getBuffer().get(rawBuffer, lumaSize + chromaSize, chromaSize);
    inAlloc.copyFromUnchecked(rawBuffer);

    // prepare output Allocation for RenderScript
    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Allocation outAlloc = Allocation.createFromBitmap(rs, bmp, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);

    // convert YUV to RGB colorspace
    ScriptC_yuv2rgb converter = new ScriptC_yuv2rgb(rs);
    converter.set_gYUV(inAlloc);
    converter.forEach_convert(outAlloc);
    outAlloc.copyTo(bmp);
    return bmp;
}
 
开发者ID:yohhoy,项目名称:heifreader,代码行数:29,代码来源:HeifReader.java

示例15: doInBackground

import android.media.Image; //导入方法依赖的package包/类
@Override
protected Bitmap doInBackground(Image... params) {

    if (params == null || params.length < 1 || params[0] == null) {

        L.e(" params is null ...");
        return null;
    }

    Image image = params[0];

    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();
    image.close();
    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();

    compressAndWrite(bitmap);

    return null;
}
 
开发者ID:kaixuanluo,项目名称:pc-android-controller-android,代码行数:31,代码来源:ScreenCaptureSocket.java


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