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


Java Image類代碼示例

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


Image類屬於android.media包,在下文中一共展示了Image類的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: YUV_420_888toNV21

import android.media.Image; //導入依賴的package包/類
private static byte[] YUV_420_888toNV21(Image image) {
    byte[] nv21;
    ByteBuffer yBuffer = image.getPlanes()[0].getBuffer();
    ByteBuffer uBuffer = image.getPlanes()[1].getBuffer();
    ByteBuffer vBuffer = image.getPlanes()[2].getBuffer();

    int ySize = yBuffer.remaining();
    int uSize = uBuffer.remaining();
    int vSize = vBuffer.remaining();

    nv21 = new byte[ySize + uSize + vSize];

    //U and V are swapped
    yBuffer.get(nv21, 0, ySize);
    vBuffer.get(nv21, ySize, vSize);
    uBuffer.get(nv21, ySize + vSize, uSize);

    return nv21;
}
 
開發者ID:InnoFang,項目名稱:FamilyBond,代碼行數:20,代碼來源:ImageUtil.java

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

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

示例5: onImageAvailable

import android.media.Image; //導入依賴的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");
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:25,代碼來源:VideoCaptureCamera2.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:FoxLabMakerSpace,項目名稱:SIGHT-For-the-Blind,代碼行數:23,代碼來源:ImagePreprocessor.java

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

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

示例9: startCapture

import android.media.Image; //導入依賴的package包/類
/**
 * 開始截圖. 獲取 image 麵板上的圖片.
 */
private void startCapture() {
    Image image = null;
    try {
        try {
            finalize();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        image = mImageReader.acquireLatestImage();
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (image == null) {
        L.e(" 獲取 image 為空 結束..");
        return;
    } else {
        SaveTask mSaveTask = new SaveTask();
        AsyncTaskCompat.executeParallel(mSaveTask, image);
    }
}
 
開發者ID:kaixuanluo,項目名稱:pc-android-controller-android,代碼行數:25,代碼來源:ScreenCaptureSocket.java

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

示例11: setupPreviewSizeAndImageReader

import android.media.Image; //導入依賴的package包/類
/**
 * lazily initialize ImageReader and select preview size
 */
private void setupPreviewSizeAndImageReader() {
    if (previewSize == null) {
        previewSize = cameraHelper.selectPreviewSize(openCamera);
    }

    if (imageReader == null) {
        int maxImages = 2;  // should be at least 2 according to ImageReader.acquireLatestImage() documentation
        imageReader = ImageReader.newInstance(previewSize.getWidth(), previewSize.getHeight(), ImageFormat.YUV_420_888, maxImages);
        imageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader reader) {
                Image img = reader.acquireLatestImage();
                if (img != null) {

                    // Make a in memory copy of the image to close the image from the reader as soon as possible.
                    // This helps the thread running the preview staying up to date.
                    IntensityPlane imgCopy = IntensityPlane.extract(img);
                    img.close();

                    int imageRotation = cameraHelper.getImageRotation(openCamera, getRelativeDisplayRotation());

                    presenter.onImageCaptured(imgCopy, imageRotation);
                }
            }
        }, null);
    }
}
 
開發者ID:BioID-GmbH,項目名稱:BWS-Android,代碼行數:31,代碼來源:FacialRecognitionFragment.java

示例12: processImage

import android.media.Image; //導入依賴的package包/類
public void processImage(Image image) {
    /**
     * Process image here
     * Called on every frame of video
     */
    if (!Tap.readyForNextFrame()) {
        return;
    }
    Mat mat = ImageUtil.imageToBgr(image);

    long frameTime = System.currentTimeMillis();

    long t1 = System.currentTimeMillis();
    List<Point> notUsedWhenDebug = Tap.getAll(mat,
            canvasCameraDebug.getHandContours(), canvasCameraDebug.getFingerTips());
    long t2 = System.currentTimeMillis();

    CanvasUtil.setScreenHeight(ViewUtil.getScreenHeight(this));
    canvasCameraDebug.updateInfo(
            t2 - t1, frameTime - lastFrameTime, Tap.getProcessInterval()
    );
    lastFrameTime = frameTime;
}
 
開發者ID:hgs1217,項目名稱:Paper-Melody,代碼行數:24,代碼來源:CameraDebugActivity.java

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

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

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


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