本文整理汇总了Java中android.media.ImageReader.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReader.newInstance方法的具体用法?Java ImageReader.newInstance怎么用?Java ImageReader.newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.ImageReader
的用法示例。
在下文中一共展示了ImageReader.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: 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);
}
}
示例3: createVirtualDisplay
import android.media.ImageReader; //导入方法依赖的package包/类
private void createVirtualDisplay(){
// display metrics
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int mDensity = metrics.densityDpi;
mDisplay = mWindowManager.getDefaultDisplay();
// get width and height
mDisplay.getRealSize(mRealDisplaySize);
// start capture reader
Log.e(TAG, String.format("Starting Projection: %dx%d", mRealDisplaySize.x, mRealDisplaySize.y));
if (mVirtualDisplay != null){
mVirtualDisplay.release();
}
mImageReader = ImageReader.newInstance(mRealDisplaySize.x, mRealDisplaySize.y, PixelFormat.RGBA_8888, 2);
mVirtualDisplay = mMediaProjection.createVirtualDisplay(getClass().getName(), mRealDisplaySize.x, mRealDisplaySize.y, mDensity, VIRTUAL_DISPLAY_FLAGS, mImageReader.getSurface(), null, mHandler);
}
示例4: OneCameraImpl
import android.media.ImageReader; //导入方法依赖的package包/类
/**
* Instantiates a new camera based on Camera 2 API.
*
* @param device The underlying Camera 2 device.
* @param characteristics The device's characteristics.
* @param pictureSize the size of the final image to be taken.
*/
OneCameraImpl(CameraDevice device, CameraCharacteristics characteristics, Size pictureSize) {
mDevice = device;
mCharacteristics = characteristics;
mFullSizeAspectRatio = calculateFullSizeAspectRatio(characteristics);
mCameraThread = new HandlerThread("OneCamera2");
mCameraThread.start();
mCameraHandler = new Handler(mCameraThread.getLooper());
mCaptureImageReader = ImageReader.newInstance(pictureSize.getWidth(),
pictureSize.getHeight(),
sCaptureImageFormat, 2);
mCaptureImageReader.setOnImageAvailableListener(mCaptureImageListener, mCameraHandler);
Log.d(TAG, "New Camera2 based OneCameraImpl created.");
}
示例5: initVirtualDisplay
import android.media.ImageReader; //导入方法依赖的package包/类
private void initVirtualDisplay(MediaProjectionManager manager, Intent data, int screenWidth, int screenHeight, int screenDensity) {
mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 1);
mMediaProjection = manager.getMediaProjection(Activity.RESULT_OK, data);
mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror",
screenWidth, screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mImageReader.getSurface(), null, null);
}
示例6: setUpVirtualDisplay
import android.media.ImageReader; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setUpVirtualDisplay() {
mScreen = (ViewGroup) getActivity().getWindow().getDecorView().getRootView();
// display metrics
DisplayMetrics metrics = getResources().getDisplayMetrics();
mDensity = metrics.densityDpi;
Display mDisplay = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
mDisplay.getRealSize(size);
mWidth = size.x;
mHeight = size.y;
// start capture reader
mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture", mWidth, mHeight, mDensity, flags, mImageReader.getSurface(), null, null);
size.set(mWidth, mHeight);
//create ScreenCapturer
mScreenCapturer = new ScreenSharingCapturer(getActivity(), mScreen, mImageReader);
mListener.onScreenCapturerReady();
}
示例7: screenShotPrepare
import android.media.ImageReader; //导入方法依赖的package包/类
/**
* 初始化截屏相关设置
* MediaProjectionManager -> MediaProjection -> VirtualDisplay
* */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void screenShotPrepare() {
initLooper();
// mediaProjection = MainApp.mediaProjection;
// SysUtils.hideStatusBar(this);
if(mediaProjection==null) {
log.d("screenShotPrepare mediaProjection null ");
return;
}
log.d("screenShotPrepare");
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
metrics = new DisplayMetrics();
display.getRealMetrics(metrics);
Point point = new Point();
display.getRealSize(point);
width = point.x;
height = point.y;
//将屏幕画面放入ImageReader关联的Surface中
imageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 1);
log.d("screenShotPrepare2 "+imageReader);
// imageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
// @Override
// public void onImageAvailable(ImageReader reader) {
// log.d("onImageAvailable ");
// }
// },null);
virtualDisplay = mediaProjection.createVirtualDisplay("ScreenShotDemo",
width, height, metrics.densityDpi,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
imageReader.getSurface(),
null, null/*Handler*/);
}
示例8: setUpCameraOutputs
import android.media.ImageReader; //导入方法依赖的package包/类
/**
* Sets up member variables related to camera.
*/
private void setUpCameraOutputs(int width, int height) throws CameraAccessException {
MLog.d(TAG, "setUpCameraOutputs");
String[] cameras = mCameraManager.getCameraIdList();
for (int i = 0; i < cameras.length; i++) {
MLog.d(TAG, "camera " + cameras[i]);
}
String cameraId = cameras[0];
CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
List<CameraCharacteristics.Key<?>> keys = characteristics.getKeys();
for (int i = 0; i < keys.size(); i++) {
Object val = characteristics.get(keys.get(i));
MLog.d(TAG, "characteristic " + keys.get(i) + " " + val);
}
// is it facingcamera
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
// For still image captures, we use the largest available size.
Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea());
mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2);
mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, null);
// Danger, W.R.! Attempting to use too large a preview size could exceed the camera
// bus' bandwidth limitation, resulting in gorgeous previews but the storage of
// garbage capture data.
int rotatedPreviewWidth = 500;
int rotatedPreviewHeight = 500;
int maxPreviewWidth = 500;
int maxPreviewHeight = 500;
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
maxPreviewHeight, largest);
//TODO mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
mCameraId = cameraId;
}
示例9: initializeCamera
import android.media.ImageReader; //导入方法依赖的package包/类
/**
* Initialize the camera device
*/
@SuppressLint("MissingPermission")
public void initializeCamera(Context context,
Handler backgroundHandler,
ImageReader.OnImageAvailableListener imageAvailableListener) {
// Discover the camera instance
CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
String[] camIds = {};
try {
camIds = manager.getCameraIdList();
} catch (CameraAccessException e) {
Timber.e(e, "Cam access exception getting IDs");
}
if (camIds.length < 1) {
Timber.d("No cameras found");
return;
}
String id = camIds[0];
Timber.d("Using camera id %s", id);
// Initialize the image processor
mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT,
ImageFormat.JPEG, MAX_IMAGES);
mImageReader.setOnImageAvailableListener(
imageAvailableListener, backgroundHandler);
// Open the camera resource
try {
manager.openCamera(id, mStateCallback, backgroundHandler);
} catch (CameraAccessException cae) {
Timber.e(cae, "Camera access exception");
}
}
示例10: initializeCamera
import android.media.ImageReader; //导入方法依赖的package包/类
/**
* Initialize the camera device
*/
public void initializeCamera(Context context,
Handler backgroundHandler,
ImageReader.OnImageAvailableListener imageAvailableListener) {
// Discover the camera instance
CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
String[] camIds = {};
try {
camIds = manager.getCameraIdList();
} catch (CameraAccessException e) {
Log.d(TAG, "Cam access exception getting IDs", e);
}
if (camIds.length < 1) {
Log.d(TAG, "No cameras found");
return;
}
String id = camIds[0];
Log.d(TAG, "Using camera id " + id);
// Initialize the image processor
mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT,
ImageFormat.JPEG, MAX_IMAGES);
mImageReader.setOnImageAvailableListener(
imageAvailableListener, backgroundHandler);
// Open the camera resource
try {
manager.openCamera(id, mStateCallback, backgroundHandler);
} catch (CameraAccessException cae) {
Log.d(TAG, "Camera access exception", cae);
}
}
示例11: createVirtualDisplay
import android.media.ImageReader; //导入方法依赖的package包/类
/****************************************** Factoring Virtual Display creation ****************/
private void createVirtualDisplay() {
// get width and height
final Point windowSize = new Point();
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getRealSize(windowSize);
mWidth = windowSize.x;
mHeight = windowSize.y;
// start capture reader
mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
mVirtualDisplay = sMediaProjection.createVirtualDisplay("FloSo", mWidth, mHeight, mDensity, VIRTUAL_DISPLAY_FLAGS, mImageReader.getSurface(), null, mHandler);
mImageReader.setOnImageAvailableListener(new ImageAvailableListener(), mHandler);
}
示例12: onCreate
import android.media.ImageReader; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
HandlerThread serviceThread = new HandlerThread("service_thread",
android.os.Process.THREAD_PRIORITY_BACKGROUND);
serviceThread.start();
running = false;
mediaRecorder = new MediaRecorder();
threadCount = Runtime.getRuntime().availableProcessors();
Log.d(TAG, "onCreate: threadCount" + threadCount);
executorService = Executors.newFixedThreadPool(threadCount);
HandlerThread handlerThread = new HandlerThread("Screen Record");
handlerThread.start();
screenHandler = new ScreenHandler(handlerThread.getLooper());
//get the size of the window
mWindowManager = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
// width = mWindowManager.getDefaultDisplay().getWidth() + 40;
width = mWindowManager.getDefaultDisplay().getWidth();
height = mWindowManager.getDefaultDisplay().getHeight();
//height = 2300;
Log.i(TAG, "onCreate: w is " + width + " h is " + height);
imageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2);
scheduler = Schedulers.from(executorService);
Disposable disposable =
getByteBufferObservable()
.subscribeOn(Schedulers.io())
.observeOn(scheduler)
.map(getBitmapFunction())
.subscribe(getBitmapConsumer());
compositeDisposable.add(disposable);
}
示例13: initializeCamera
import android.media.ImageReader; //导入方法依赖的package包/类
/**
* Initialize the camera device
*/
void initializeCamera(@NonNull Context context,
@NonNull Handler backgroundHandler,
@NonNull ImageReader.OnImageAvailableListener imageAvailableListener) {
mBackgroundHandler = backgroundHandler;
// Discover the camera instance
CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
String[] camIds = {};
try {
camIds = manager.getCameraIdList();
} catch (CameraAccessException e) {
Log.e(TAG, "Cam access exception getting IDs", e);
}
if (camIds.length < 1) {
Log.e(TAG, "No cameras found");
return;
}
String id = camIds[0];
Log.d(TAG, "Using camera id " + id);
// Initialize the image processor
mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT, ImageFormat.JPEG, MAX_IMAGES);
mImageReader.setOnImageAvailableListener(imageAvailableListener, backgroundHandler);
// Open the camera resource
try {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "initializeCamera: Camera permission not available.");
return;
}
manager.openCamera(id, mStateCallback, backgroundHandler);
} catch (CameraAccessException cae) {
Log.d(TAG, "Camera access exception", cae);
}
}
示例14: initializeCamera
import android.media.ImageReader; //导入方法依赖的package包/类
/**
* Initialize the camera device
*/
public void initializeCamera(Context context,
Handler backgroundHandler,
ImageReader.OnImageAvailableListener imageAvailableListener) {
// Discover the camera instance
CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
String[] camIds = {};
try {
camIds = manager.getCameraIdList();
} catch (CameraAccessException e) {
Log.d(TAG, "Cam access exception getting IDs", e);
}
if (camIds.length < 1) {
Log.d(TAG, "No cameras found");
return;
}
String id = camIds[0];
Log.d(TAG, "Using camera id " + id);
// Initialize the image processor
mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT,
ImageFormat.JPEG, MAX_IMAGES);
mImageReader.setOnImageAvailableListener(
imageAvailableListener, backgroundHandler);
// Open the camera resource
try {
manager.openCamera(id, mStateCallback, backgroundHandler);
} catch (CameraAccessException cae) {
Log.d(TAG, "Camera access exception", cae);
}
}
示例15: ScreenGrabber
import android.media.ImageReader; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private ScreenGrabber(MediaProjection mediaProjection, DisplayMetrics raw) {
rawDisplayMetrics = raw;
projection = mediaProjection;
imageReader = ImageReader.newInstance(rawDisplayMetrics.widthPixels, rawDisplayMetrics.heightPixels,
PixelFormat.RGBA_8888, 2);
virtualDisplay = projection.createVirtualDisplay("screen-mirror", rawDisplayMetrics.widthPixels,
rawDisplayMetrics.heightPixels,
rawDisplayMetrics.densityDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, imageReader.getSurface(),
null, null);
}