當前位置: 首頁>>代碼示例>>Java>>正文


Java Image.getPlanes方法代碼示例

本文整理匯總了Java中android.media.Image.getPlanes方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.getPlanes方法的具體用法?Java Image.getPlanes怎麽用?Java Image.getPlanes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.Image的用法示例。


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

import android.media.Image; //導入方法依賴的package包/類
private static byte[] toByteArray(Image image) {
    byte[] data = null;
    if (image.getFormat() == ImageFormat.JPEG) {
        Image.Plane[] planes = image.getPlanes();
        ByteBuffer buffer = planes[0].getBuffer();
        data = new byte[buffer.capacity()];
        buffer.get(data);
        return data;
    } else if (image.getFormat() == ImageFormat.YUV_420_888) {
        data = NV21toJPEG(
                YUV_420_888toNV21(image),
                image.getWidth(), image.getHeight());
    } else {
        Log.w(TAG, "Unrecognized image format: " + image.getFormat());
    }
    return data;
}
 
開發者ID:Xlythe,項目名稱:CameraView,代碼行數:18,代碼來源:PictureSession.java

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

示例6: Serialize

import android.media.Image; //導入方法依賴的package包/類
public static byte[] Serialize(Image image)
{
    if (image==null)
        return null;

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

    // NV21 expects planes in order YVU, not YUV:
    if (image.getFormat() == ImageFormat.YUV_420_888)
        planes = new Image.Plane[] {planes[0], planes[2], planes[1]};

    byte[] serializeBytes = new byte[getSerializedSize(image)];
    int nextFree = 0;

    for (Image.Plane plane: planes)
    {
        ByteBuffer buffer = plane.getBuffer();
        buffer.position(0);
        int nBytes = buffer.remaining();
        plane.getBuffer().get(serializeBytes, nextFree, nBytes);
        nextFree += nBytes;
    }

    return serializeBytes;
}
 
開發者ID:tschaumburg,項目名稱:FastBarcodeScanner,代碼行數:26,代碼來源:ImageDecoder.java

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

示例8: CentralSpiralIterator

import android.media.Image; //導入方法依賴的package包/類
public CentralSpiralIterator(Image image, Rect area, boolean duplicateBuffer) {
    super(image, area, duplicateBuffer);
    Image.Plane plane = image.getPlanes()[0];
    mPixelStride = mNextStepSkip = plane.getPixelStride();
    mRowStride = plane.getRowStride();
    mByteBuffer.position(area.centerX() * mPixelStride + area.centerY() * mRowStride);
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:8,代碼來源:ColorIterator.java

示例9: imageToByteArray

import android.media.Image; //導入方法依賴的package包/類
public static byte[] imageToByteArray(Image image) {
    byte[] data = null;
    if (image.getFormat() == ImageFormat.JPEG) {
        Image.Plane[] planes = image.getPlanes();
        ByteBuffer buffer = planes[0].getBuffer();
        data = new byte[buffer.capacity()];
        buffer.get(data);
        return data;
    } else if (image.getFormat() == ImageFormat.YUV_420_888) {
        data = NV21toJPEG(
                YUV_420_888toNV21(image),
                image.getWidth(), image.getHeight());
    }
    return data;
}
 
開發者ID:InnoFang,項目名稱:FamilyBond,代碼行數:16,代碼來源:ImageUtil.java

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

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

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

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

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

示例15: 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:hyb1996,項目名稱:Auto.js,代碼行數:13,代碼來源:Images.java


注:本文中的android.media.Image.getPlanes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。