当前位置: 首页>>代码示例>>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;未经允许,请勿转载。