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


Java ImageReader類代碼示例

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


ImageReader類屬於android.media包,在下文中一共展示了ImageReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: imageAvailable

import android.media.ImageReader; //導入依賴的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: readyCamera

import android.media.ImageReader; //導入依賴的package包/類
public void readyCamera() {
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        String pickedCamera = getCamera(manager);
        if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        manager.openCamera(pickedCamera, cameraStateCallback, null);
        imageReader = ImageReader.newInstance(videoWidth, videoHeight, 0x00000001 /*ImageFormat.YUV_420_888*/, 2 /* images buffered */);
        imageReader.setOnImageAvailableListener(onImageAvailableListener, null);
        Log.i(TAG, "imageReader created");
    } catch (CameraAccessException e){
        Log.e(TAG, e.getMessage());
    }
}
 
開發者ID:galme,項目名稱:ROLF-EV3,代碼行數:23,代碼來源:PCVideoStreamer.java

示例3: onImageAvailable

import android.media.ImageReader; //導入依賴的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: createVirtualEnvironment

import android.media.ImageReader; //導入依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void createVirtualEnvironment() {
    dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");
    strDate = dateFormat.format(new java.util.Date());
    pathImage = Environment.getExternalStorageDirectory().getPath() + "/Pictures/";
    nameImage = pathImage + strDate + ".png";
    mMediaProjectionManager1 = (MediaProjectionManager) activity.getApplication().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    mWindowManager1 = (WindowManager) activity.getApplication().getSystemService(Context.WINDOW_SERVICE);
    windowWidth = ViewUtil.getScreenWidth(activity);
    windowHeight = ViewUtil.getSceenHeight(activity);
    metrics = new DisplayMetrics();
    mWindowManager1.getDefaultDisplay().getMetrics(metrics);
    mScreenDensity = metrics.densityDpi;
    mImageReader = ImageReader.newInstance(windowWidth, windowHeight, 0x1, 2); //ImageFormat.RGB_565

    LogUtil.d(TAG, "prepared the virtual environment");
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:18,代碼來源:ScreenCapture.java

示例5: onImageAvailable

import android.media.ImageReader; //導入依賴的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: setImageListener

import android.media.ImageReader; //導入依賴的package包/類
private void setImageListener(Handler handler) {
    mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
        @Override
        public void onImageAvailable(ImageReader reader) {
            if (mImageAvailable) {
                return;
            }
            mLatestImage = reader.acquireLatestImage();
            if (mLatestImage != null) {
                mImageAvailable = true;
                synchronized (mImageWaitingLock) {
                    mImageWaitingLock.notify();
                }
            }
        }
    }, handler);
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:18,代碼來源:ScreenCapturer.java

示例7: onImageAvailable

import android.media.ImageReader; //導入依賴的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: createVirtualDisplay

import android.media.ImageReader; //導入依賴的package包/類
/****************************************** Factoring Virtual Display creation ****************/

    private void createVirtualDisplay() {
        // get width and height
        Point size = new Point();
        mDisplay.getRealSize(size);
        mWidth = size.x;
        mHeight = size.y;
        mDisplayMetrics = new DisplayMetrics();
        mDisplay.getRealMetrics(mDisplayMetrics);

        if (SmingManager.getInstance().isSaveScreenshot() == false) {
            if (mWidth > SmingManager.getInstance().getSmingHalfWidth()) {
                float downScale = (float) SmingManager.getInstance().getSmingHalfWidth() / mWidth;
                mWidth *= downScale;
                mHeight *= downScale;
                mHeight += 2;
            }
        }

        // start capture reader
        mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
        mVirtualDisplay = sMediaProjection.createVirtualDisplay(SCREENCAP_NAME, mWidth, mHeight, mDensity, VIRTUAL_DISPLAY_FLAGS, mImageReader.getSurface(), null, mHandler);
        mImageReader.setOnImageAvailableListener(new ImageAvailableListener(), mHandler);
    }
 
開發者ID:monthlypub,項目名稱:SmingZZick_App,代碼行數:26,代碼來源:ScreenCaptureService.java

示例9: setupPreviewSizeAndImageReader

import android.media.ImageReader; //導入依賴的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

示例10: initCapture

import android.media.ImageReader; //導入依賴的package包/類
public void initCapture(Context context, MediaProjection mediaProjection, final String path, final IRecordShotCallback callback){
    int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    int screenHeight = context.getResources().getDisplayMetrics().heightPixels;

    // thread for image checking
    mCheckThread = new HandlerThread("CheckHandler");
    mCheckThread.start();
    mCheckHandler = new Handler(mCheckThread.getLooper());

    try {
        mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 2);
        mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader reader) {
                imageAvailable(reader, path, callback);
            }
        }, mCheckHandler);
        mSurface = mImageReader.getSurface();
    }finally {

    }
    mVirtualDisplay = mediaProjection.createVirtualDisplay("mediaprojection", screenWidth, screenHeight,
            1, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mSurface, null, null);
}
 
開發者ID:sunshinecoast,項目名稱:ScreenRecordCaptureMaster,代碼行數:25,代碼來源:CaptureScreenImage.java

示例11: Shotter

import android.media.ImageReader; //導入依賴的package包/類
public Shotter(Context context, Intent data) {
    this.mRefContext = new SoftReference<>(context);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {


        mMediaProjection = getMediaProjectionManager().getMediaProjection(Activity.RESULT_OK,
                data);

        mImageReader = ImageReader.newInstance(
                getScreenWidth(),
                getScreenHeight(),
                PixelFormat.RGBA_8888,//此處必須和下麵 buffer處理一致的格式 ,RGB_565在一些機器上出現兼容問題。
                1);
    }
}
 
開發者ID:weizongwei5,項目名稱:AndroidScreenShot_SysApi,代碼行數:17,代碼來源:Shotter.java

示例12: onImageAvailable

import android.media.ImageReader; //導入依賴的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

示例13: onOpened

import android.media.ImageReader; //導入依賴的package包/類
@Override
public void onOpened(final CameraDevice cameraDevice, final ImageReader imageReader,
        final Handler cameraHandler, final Rotation rotation, final boolean flipHorizontal,
        final boolean flipVertical) {
    if (!isResumed() || !CheckUtil.nonNull(mProcessorChain)) {
        return;
    }
    mProcessorChain.onCameraOpened(rotation, flipHorizontal, flipVertical,
            surfaceTexture -> {
                // fix MX5 preview not show bug: http://stackoverflow.com/a/34337226/3077508
                surfaceTexture.setDefaultBufferSize(mPreviewWidth, mPreviewHeight);
                Surface surface = new Surface(surfaceTexture);
                List<Surface> targets = Arrays.asList(surface, imageReader.getSurface());
                mCamera2Helper.outputTargetChanged(targets);
                startPreviewDirectly(cameraDevice, targets, mIsDefaultFlashOpen, cameraHandler);
            });
}
 
開發者ID:Piasy,項目名稱:CameraCompat,代碼行數:18,代碼來源:Camera2PreviewFragment.java

示例14: onImageAvailable

import android.media.ImageReader; //導入依賴的package包/類
@Override
public void onImageAvailable(ImageReader reader)
{
    Activity activity = getActivity();

    if(null == mTextureView || null == mPreviewSize || null == activity)
    {
        return;
    }

    try
    {
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);

        mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(),
                getJpegOrientation(characteristics, rotation)));
    }
    catch(CameraAccessException e)
    {
        LogExt.e(getClass(), e);
    }
}
 
開發者ID:ResearchStack,項目名稱:MoleMapperAndroid,代碼行數:25,代碼來源:LollipopCameraFragment.java

示例15: onImageAvailable

import android.media.ImageReader; //導入依賴的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


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