Java Code Examples for android.hardware.Camera.Size

The following are top voted examples for showing how to use android.hardware.Camera.Size. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: react-native-webrtc   File: WebRTCModule.java   Source Code and License 8 votes vote down vote up
@SuppressWarnings("deprecation")
public WritableMap getCameraInfo(int index) {
    CameraInfo info = new CameraInfo();

    Size size = null;
    try {
        Camera.getCameraInfo(index, info);
        Camera camera = Camera.open(index);
        size = getMaxSupportedVideoSize(camera);
        camera.release();
    } catch (Exception var3) {
        Logging.e("CameraEnumerationAndroid", "getCameraInfo failed on index " + index, var3);

        return null;
    }
    WritableMap params = Arguments.createMap();
    String facing = info.facing == 1 ? "front" : "back";
    params.putString("label", "Camera " + index + ", Facing " + facing + ", Orientation " + info.orientation);
    params.putString("id", "" + index);
    params.putString("facing", facing);
    params.putString("kind", "video");
    params.putString("maxWidth", String.valueOf(size.width));
    params.putString("maxHeight", String.valueOf(size.height));

    return params;
}
 
Example 2
Project: QRCodeScanner   File: BarcodeCameraConfig.java   Source Code and License 7 votes vote down vote up
public BarcodeCameraConfig configPreviewSize2(int viewWidth, int viewHeight) {
    Parameters params = camera.getParameters();
    List<Size> sizes = params.getSupportedPreviewSizes();
    if (sizes == null || sizes.size() <= 0) {
        return this;
    }

    Size bestSize = null;
    int diff = Integer.MAX_VALUE;

    for (Size tmpSize : sizes) {
        int newDiff = Math.abs(tmpSize.width - viewWidth) + Math.abs(tmpSize.height - viewHeight);
        if (newDiff == 0) {
            bestSize = tmpSize;
            break;
        } else if (newDiff < diff) {
            bestSize = tmpSize;
            diff = newDiff;
        }
    }
    params.setPreviewSize(bestSize.width, bestSize.height);
    camera.setParameters(params);
    return this;
}
 
Example 3
Project: react-native-webrtc   File: WebRTCModule.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("deprecation")
private Size getMaxSupportedVideoSize(Camera camera) {

    List<Camera.Size> sizes;

    if (camera.getParameters().getSupportedVideoSizes() != null) {
        sizes = camera.getParameters().getSupportedVideoSizes();
    } else {
        // Video sizes may be null, which indicates that all the supported
        // preview sizes are supported for video recording.
        sizes = camera.getParameters().getSupportedPreviewSizes();
    }

    int maxWidth = sizes.get(0).width;
    int maxHeight = sizes.get(0).height;

    for (Camera.Size size : sizes) {
        if (size.height > maxWidth && size.width > maxHeight) {
            maxWidth = size.width;
            maxHeight = size.height;
        }
    }

    return new Size(maxWidth, maxHeight);
}
 
Example 4
Project: FaceRecognition   File: CamParaUtil.java   Source Code and License 6 votes vote down vote up
public Size getPropPreviewSize(List<Size> list, float th, int minWidth){
	Collections.sort(list, sizeComparator);

	int i = 0;
	for(Size s:list){
		if((s.width >= minWidth) && equalRate(s, th)){
			Log.i(TAG, "PreviewSize:w = " + s.width + "h = " + s.height);
			break;
		}
		i++;
	}
	if(i == list.size()){
		i = 0;//���û�ҵ�����ѡ��С��size
	}
	return list.get(i);
}
 
Example 5
Project: FaceRecognition   File: CamParaUtil.java   Source Code and License 6 votes vote down vote up
public Size getPropPictureSize(List<Size> list, float th, int minWidth){
	Collections.sort(list, sizeComparator);

	int i = 0;
	for(Size s:list){
		if((s.width >= minWidth) && equalRate(s, th)){
			Log.i(TAG, "PictureSize : w = " + s.width + "h = " + s.height);
			break;
		}
		i++;
	}
	if(i == list.size()){
		i = 0;//���û�ҵ�����ѡ��С��size
	}
	return list.get(i);
}
 
Example 6
Project: WeiXinRecordedDemo   File: MediaRecorderBase.java   Source Code and License 6 votes vote down vote up
/** 设置回调 */
protected void setPreviewCallback() {
	Size size = mParameters.getPreviewSize();
	if (size != null) {
		PixelFormat pf = new PixelFormat();
		PixelFormat.getPixelFormatInfo(mParameters.getPreviewFormat(), pf);
		int buffSize = size.width * size.height * pf.bitsPerPixel / 8;
		try {
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.setPreviewCallbackWithBuffer(this);
		} catch (OutOfMemoryError e) {
			Log.e("Yixia", "startPreview...setPreviewCallback...", e);
		}
		Log.e("Yixia", "startPreview...setPreviewCallbackWithBuffer...width:" + size.width + " height:" + size.height);
	} else {
		camera.setPreviewCallback(this);
	}
}
 
Example 7
Project: WeiXinRecordedDemo   File: MediaRecorderBase.java   Source Code and License 6 votes vote down vote up
/** 设置回调 */
protected void setPreviewCallback() {
	Size size = mParameters.getPreviewSize();
	if (size != null) {
		PixelFormat pf = new PixelFormat();
		PixelFormat.getPixelFormatInfo(mParameters.getPreviewFormat(), pf);
		int buffSize = size.width * size.height * pf.bitsPerPixel / 8;
		try {
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.setPreviewCallbackWithBuffer(this);
		} catch (OutOfMemoryError e) {
			Log.e("Yixia", "startPreview...setPreviewCallback...", e);
		}
		Log.e("Yixia", "startPreview...setPreviewCallbackWithBuffer...width:" + size.width + " height:" + size.height);
	} else {
		camera.setPreviewCallback(this);
	}
}
 
Example 8
Project: PeSanKita-android   File: CameraView.java   Source Code and License 6 votes vote down vote up
private Rect getCroppedRect(Size cameraPreviewSize, Rect visibleRect, int rotation) {
  final int previewWidth  = cameraPreviewSize.width;
  final int previewHeight = cameraPreviewSize.height;

  if (rotation % 180 > 0) rotateRect(visibleRect);

  float scale = (float) previewWidth / visibleRect.width();
  if (visibleRect.height() * scale > previewHeight) {
    scale = (float) previewHeight / visibleRect.height();
  }
  final float newWidth  = visibleRect.width()  * scale;
  final float newHeight = visibleRect.height() * scale;
  final float centerX   = (VERSION.SDK_INT < 14 || isTroublemaker()) ? previewWidth - newWidth / 2 : previewWidth / 2;
  final float centerY   = previewHeight / 2;

  visibleRect.set((int) (centerX - newWidth  / 2),
                  (int) (centerY - newHeight / 2),
                  (int) (centerX + newWidth  / 2),
                  (int) (centerY + newHeight / 2));

  if (rotation % 180 > 0) rotateRect(visibleRect);
  return visibleRect;
}
 
Example 9
Project: PaoMovie   File: MagicCameraDisplay.java   Source Code and License 6 votes vote down vote up
private void setUpCamera(){
mGLSurfaceView.queueEvent(new Runnable() {
     		
          @Override
          public void run() {
          	if(mTextureId == OpenGLUtils.NO_TEXTURE){
      			mTextureId = OpenGLUtils.getExternalOESTextureID();	
      			mSurfaceTexture = new SurfaceTexture(mTextureId);
  				mSurfaceTexture.setOnFrameAvailableListener(mOnFrameAvailableListener);   
          	}
          	Size size = CameraEngine.getPreviewSize();
  			int orientation = CameraEngine.getOrientation();
  			if(orientation == 90 || orientation == 270){
  				mImageWidth = size.height;
  				mImageHeight = size.width;
  			}else{
  				mImageWidth = size.width;
  				mImageHeight = size.height;
  			} 
  			mCameraInputFilter.onOutputSizeChanged(mImageWidth, mImageHeight);
          	CameraEngine.startPreview(mSurfaceTexture);
          }
      });
  }
 
Example 10
Project: mao-android   File: CameraRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public void onPreviewFrame(final byte[] data, final Camera camera) {
    log.d("onPreviewFrame");
    final Size previewSize = camera.getParameters().getPreviewSize();
    if (mGLRgbBuffer == null) {
        mGLRgbBuffer = IntBuffer.allocate(previewSize.width * previewSize.height);
    }
    if (mRunOnDraw.isEmpty()) {
        runOnDraw(new Runnable() {
            @Override
            public void run() {
                YuvDecoder.YUVtoRBGA(data, previewSize.width, previewSize.height, mGLRgbBuffer.array());
                mGLTextureId = OpenGlUtils.loadTexture(mGLRgbBuffer, previewSize, mGLTextureId);
                camera.addCallbackBuffer(data);

                if (mImageWidth != previewSize.width) {
                    mImageWidth = previewSize.width;
                    mImageHeight = previewSize.height;
                    adjustImageScaling();
                }
            }
        });
    }
}
 
Example 11
Project: mao-android   File: OpenGlUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 12
Project: Cable-Android   File: CameraView.java   Source Code and License 6 votes vote down vote up
private Rect getCroppedRect(Size cameraPreviewSize, Rect visibleRect, int rotation) {
  final int previewWidth  = cameraPreviewSize.width;
  final int previewHeight = cameraPreviewSize.height;

  if (rotation % 180 > 0) rotateRect(visibleRect);

  float scale = (float) previewWidth / visibleRect.width();
  if (visibleRect.height() * scale > previewHeight) {
    scale = (float) previewHeight / visibleRect.height();
  }
  final float newWidth  = visibleRect.width()  * scale;
  final float newHeight = visibleRect.height() * scale;
  final float centerX   = (VERSION.SDK_INT < 14 || isTroublemaker()) ? previewWidth - newWidth / 2 : previewWidth / 2;
  final float centerY   = previewHeight / 2;

  visibleRect.set((int) (centerX - newWidth  / 2),
                  (int) (centerY - newHeight / 2),
                  (int) (centerX + newWidth  / 2),
                  (int) (centerY + newHeight / 2));

  if (rotation % 180 > 0) rotateRect(visibleRect);
  return visibleRect;
}
 
Example 13
Project: meipai-Android   File: MediaRecorderBase.java   Source Code and License 6 votes vote down vote up
/** 设置回调 */
protected void setPreviewCallback() {
	Size size = mParameters.getPreviewSize();
	if (size != null) {
		PixelFormat pf = new PixelFormat();
		PixelFormat.getPixelFormatInfo(mParameters.getPreviewFormat(), pf);
		int buffSize = size.width * size.height * pf.bitsPerPixel / 8;
		try {
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.setPreviewCallbackWithBuffer(this);
		} catch (OutOfMemoryError e) {
			Log.e("Yixia", "startPreview...setPreviewCallback...", e);
		}
		Log.e("Yixia", "startPreview...setPreviewCallbackWithBuffer...width:" + size.width + " height:" + size.height);
	} else {
		camera.setPreviewCallback(this);
	}
}
 
Example 14
Project: live_master   File: CamParaUtil.java   Source Code and License 6 votes vote down vote up
public  Size getPreviewSize(List<Camera.Size> list, int width,float th){
	Collections.sort(list, sizeComparator);

	float rate = 1.77f;
	if (Math.abs(th-1.33f)<Math.abs(th-1.77f)){
		rate = 1.33f;
	}else{
		rate = 1.77f;
	}
	int i = 0;
	for(Size s:list){
		if((s.height > width) && equalRate(s, rate)){
			Log.i(TAG, "最终设置预览尺寸:w = " + s.width + "h = " + s.height+","+rate);
			break;
		}
		i++;
	}

	return list.get(i);
}
 
Example 15
Project: live_master   File: CamParaUtil.java   Source Code and License 6 votes vote down vote up
public Size getPropPictureSize(List<Size> list, float th, int minWidth){
	Collections.sort(list, sizeComparator);

	int i = 0;
	for(Size s:list){
		if((s.width >= minWidth) && equalRate(s, th)){
			Log.i(TAG, "PictureSize : w = " + s.width + "h = " + s.height);
			break;
		}
		i++;
	}
	if(i == list.size()){
		i = 0;//���û�ҵ�����ѡ��С��size
	}
	return list.get(i);
}
 
Example 16
Project: TAG   File: GPUImageRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public void onPreviewFrame(final byte[] data, final Camera camera) {
    final Size previewSize = camera.getParameters().getPreviewSize();
    if (mGLRgbBuffer == null) {
        mGLRgbBuffer = IntBuffer.allocate(previewSize.width * previewSize.height);
    }
    if (mRunOnDraw.isEmpty()) {
        runOnDraw(new Runnable() {
            @Override
            public void run() {
                GPUImageNativeLibrary.YUVtoRBGA(data, previewSize.width, previewSize.height,
                        mGLRgbBuffer.array());
                mGLTextureId = OpenGlUtils.loadTexture(mGLRgbBuffer, previewSize, mGLTextureId);
                camera.addCallbackBuffer(data);

                if (mImageWidth != previewSize.width) {
                    mImageWidth = previewSize.width;
                    mImageHeight = previewSize.height;
                    adjustImageScaling();
                }
            }
        });
    }
}
 
Example 17
Project: TAG   File: OpenGlUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 18
Project: PreRect   File: CameraConfigurationManager.java   Source Code and License 6 votes vote down vote up
public void setDesiredCameraParameters(Camera camera, int caremaId) {
	Camera.Parameters parameters = camera.getParameters();
	parameters.setPreviewFormat(ImageFormat.NV21);
	parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
	setZoom(parameters);

	camera.setDisplayOrientation(getDisplayOrientation(caremaId));

	// 设置照片尺寸
	if (this.pictureSize == null) {
		WindowManager manager = (WindowManager) mContext
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		List<Size> pictureSizes = parameters.getSupportedPictureSizes();
		this.setPicutreSize(pictureSizes, display.getWidth(),
				display.getHeight());
	}
	try {
		parameters.setPictureSize(this.pictureSize.width,
				this.pictureSize.height);
	} catch (Exception e) {
		e.printStackTrace();
	}
	camera.setParameters(parameters);
}
 
Example 19
Project: ROLF-EV3   File: VideoQuality.java   Source Code and License 6 votes vote down vote up
/** 
 * Checks if the requested resolution is supported by the camera.
 * If not, it modifies it by supported parameters. 
 **/
public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
	VideoQuality v = quality.clone();
	int minDist = Integer.MAX_VALUE;
	String supportedSizesStr = "Supported resolutions: ";
	List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
	for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
		Size size = it.next();
		supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
		int dist = Math.abs(quality.resX - size.width);
		if (dist<minDist) {
			minDist = dist;
			v.resX = size.width;
			v.resY = size.height;
		}
	}
	Log.v(TAG, supportedSizesStr);
	if (quality.resX != v.resX || quality.resY != v.resY) {
		Log.v(TAG,"Resolution modified: "+quality.resX+"x"+quality.resY+"->"+v.resX+"x"+v.resY);
	}
	
	return v;
}
 
Example 20
Project: VideoCamera   File: CameraWrapper.java   Source Code and License 6 votes vote down vote up
@TargetApi(VERSION_CODES.HONEYCOMB)
protected List<Size> getSupportedVideoSizes(int currentSdkInt) {
    Parameters params = mNativeCamera.getNativeCameraParameters();

    List<Size> supportedVideoSizes;
    if (currentSdkInt < Build.VERSION_CODES.HONEYCOMB) {
        CLog.e(CLog.CAMERA, "Using supportedPreviewSizes iso supportedVideoSizes due to API restriction");
        supportedVideoSizes = params.getSupportedPreviewSizes();
    } else if (params.getSupportedVideoSizes() == null) {
        CLog.e(CLog.CAMERA, "Using supportedPreviewSizes because supportedVideoSizes is null");
        supportedVideoSizes = params.getSupportedPreviewSizes();
    } else {
        supportedVideoSizes = params.getSupportedVideoSizes();
    }

    return supportedVideoSizes;
}
 
Example 21
Project: AndroidCamera   File: GPUImageRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public void onPreviewFrame(final byte[] data, final Camera camera) {
    final Size previewSize = camera.getParameters().getPreviewSize();
    if (mGLRgbBuffer == null) {
        mGLRgbBuffer = IntBuffer.allocate(previewSize.width * previewSize.height);
    }
    if (mRunOnDraw.isEmpty()) {
        runOnDraw(new Runnable() {
            @Override
            public void run() {
                GPUImageNativeLibrary.YUVtoRBGA(data, previewSize.width, previewSize.height,
                        mGLRgbBuffer.array());
                mGLTextureId = OpenGlUtils.loadTexture(mGLRgbBuffer, previewSize, mGLTextureId);
                camera.addCallbackBuffer(data);

                if (mImageWidth != previewSize.width) {
                    mImageWidth = previewSize.width;
                    mImageHeight = previewSize.height;
                    adjustImageScaling();
                }
            }
        });
    }
}
 
Example 22
Project: AndroidCamera   File: OpenGlUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 23
Project: VisiSynth   File: Preview.java   Source Code and License 6 votes vote down vote up
public void onPreviewFrame(byte[] data, Camera camera){
    Log.d("TAG", "frame1 "+data.length);
    Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
    YuvImage yuvimage=new YuvImage(data, ImageFormat.NV21, previewSize.width, previewSize.height, null);

    // Convert to Bitmap
    final double [][] imgmat = imgpro.BufferedYUVImage2Mat(yuvimage.getYuvData(),
            yuvimage.getWidth(), yuvimage.getHeight(), 640, 480);

    List<Double> ld = imgpro.AnalyzeMat(imgmat, 0.6);

    String logline = "points:";
    for(Double p : ld)
        logline += " " + (1-p);
    Log.d("TAG", logline);
    double [] f = new double[ld.size()];
    for(int i = 0; i < f.length; i ++)
        f[i] = Math.pow(2.0, ld.get(i) * 2) * 440.0;
    play(f);
}
 
Example 24
Project: CommunityService   File: CameraConfigurationManager.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the camera up to take preview images which are used for both preview and decoding.
 * We detect the preview format here so that buildLuminanceSource() can build an appropriate
 * LuminanceSource subclass. In the future we may want to force YUV420SP as it's the smallest,
 * and the planar Y can be used for barcode scanning without a copy in some cases.
 */
void setDesiredCameraParameters(Camera camera) {
	Camera.Parameters parameters = camera.getParameters();
	List<Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
	int position =0;
	if(supportedPreviewSizes.size()>2){
		position=supportedPreviewSizes.size()/2+1;//supportedPreviewSizes.get();
	}else {
		position=supportedPreviewSizes.size()/2;
	}

	int width = supportedPreviewSizes.get(position).width;
	int height = supportedPreviewSizes.get(position).height;
	Log.d(TAG, "Setting preview size: " + cameraResolution);
	camera.setDisplayOrientation(90);  
	cameraResolution.x=width;
	cameraResolution.y=height;
	parameters.setPreviewSize(width,height);
	setFlash(parameters);
	setZoom(parameters);
	//setSharpness(parameters);
	camera.setParameters(parameters);
}
 
Example 25
Project: miku   File: GPUImageRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public void onPreviewFrame(final byte[] data, final Camera camera) {
  final Size previewSize = camera.getParameters().getPreviewSize();
  if (mGLRgbBuffer == null) {
    mGLRgbBuffer = IntBuffer.allocate(previewSize.width * previewSize.height);
  }
  if (mRunOnDraw.isEmpty()) {
    runOnDraw(new Runnable() {
      @Override
      public void run() {
        GPUImageNativeLibrary.YUVtoRBGA(data, previewSize.width, previewSize.height,
            mGLRgbBuffer.array());
        mGLTextureId = OpenGlUtils.loadTexture(mGLRgbBuffer, previewSize, mGLTextureId);
        camera.addCallbackBuffer(data);

        if (mImageWidth != previewSize.width) {
          mImageWidth = previewSize.width;
          mImageHeight = previewSize.height;
          adjustImageScaling();
        }
      }
    });
  }
}
 
Example 26
Project: ArCamera   File: CamParaUtil.java   Source Code and License 6 votes vote down vote up
public  Size getPropPreviewSize(List<Size> list, float th, int minWidth){
	Collections.sort(list, sizeComparator);

	int i = 0;
	for(Size s:list){
		if((s.width >= minWidth) && equalRate(s, th)){
			Log.i(TAG, "PreviewSize:w = " + s.width + "h = " + s.height);
			break;
		}
		i++;
	}
	if(i == list.size()){
		i = 0;//���û�ҵ�����ѡ��С��size
	}
	return list.get(i);
}
 
Example 27
Project: ArCamera   File: CamParaUtil.java   Source Code and License 6 votes vote down vote up
public Size getPropPictureSize(List<Size> list, float th, int minWidth){
	Collections.sort(list, sizeComparator);

	int i = 0;
	for(Size s:list){
		if((s.width >= minWidth) && equalRate(s, th)){
			Log.i(TAG, "PictureSize : w = " + s.width + "h = " + s.height);
			break;
		}
		i++;
	}
	if(i == list.size()){
		i = 0;//���û�ҵ�����ѡ��С��size
	}
	return list.get(i);
}
 
Example 28
Project: Document-Scanner   File: DocumentCameraView.java   Source Code and License 6 votes vote down vote up
public void setMaxPictureResolution() {
    int maxWidth=0;
    Size curRes=null;
    for ( Size r: getPictureResolutionList() ) {
        Log.d(TAG,"supported picture resolution: "+r.width+"x"+r.height);
        if (r.width>maxWidth) {
            maxWidth=r.width;
            curRes=r;
        }
    }

    if (curRes!=null) {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPictureSize(curRes.width, curRes.height);
        mCamera.setParameters(parameters);
        Log.d(TAG, "selected picture resolution: " + curRes.width + "x" + curRes.height);
    }

    return;
}
 
Example 29
Project: Document-Scanner   File: DocumentCameraView.java   Source Code and License 6 votes vote down vote up
public void setMaxPreviewResolution() {
    int maxWidth=0;
    Size curRes=null;

    mCamera.lock();

    for ( Size r: getResolutionList() ) {
        if (r.width>maxWidth) {
            Log.d(TAG,"supported preview resolution: "+r.width+"x"+r.height);
            maxWidth=r.width;
            curRes=r;
        }
    }

    if (curRes!=null) {
        setResolution(curRes);
        Log.d(TAG, "selected preview resolution: " + curRes.width + "x" + curRes.height);
    }

    return;
}
 
Example 30
Project: prayer-times-android   File: CameraSurfaceView.java   Source Code and License 6 votes vote down vote up
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    if (mCamera == null) {
        return;
    }
    // Now that the size is known, set up the camera parameters and begin
    // the preview.

    Camera.Parameters parameters = mCamera.getParameters();
    Size size = getBestPreviewSize(width, height, parameters);
    if (size != null) {
        parameters.setPreviewSize(size.width, size.height);
    }
    mCamera.setParameters(parameters);

    try {
        mCamera.startPreview();
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
}
 
Example 31
Project: prayer-times-android   File: CameraSurfaceView.java   Source Code and License 6 votes vote down vote up
@Nullable
private Camera.Size getBestPreviewSize(int width, int height, @NonNull Camera.Parameters parameters) {
    Camera.Size result = null;
    double aspect = width / (double) height;
    for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
        if ((size.width >= width) && (size.height >= height)) {
            if (result == null) {
                result = size;
            } else {
                if (Math.abs((result.width / (double) result.height - aspect))
                        > Math.abs((size.width / (double) size.height - aspect))) {
                    result = size;
                }
            }
        }
    }

    return result;
}
 
Example 32
Project: Android_CCTV   File: VideoQuality.java   Source Code and License 6 votes vote down vote up
/** 
 * Checks if the requested resolution is supported by the camera.
 * If not, it modifies it by supported parameters. 
 **/
public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
	VideoQuality v = quality.clone();
	int minDist = Integer.MAX_VALUE;
	String supportedSizesStr = "Supported resolutions: ";
	List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
	for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
		Size size = it.next();
		supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
		int dist = Math.abs(quality.resX - size.width);
		if (dist<minDist) {
			minDist = dist;
			v.resX = size.width;
			v.resY = size.height;
		}
	}
	Log.v(TAG, supportedSizesStr);
	if (quality.resX != v.resX || quality.resY != v.resY) {
		Log.v(TAG,"Resolution modified: "+quality.resX+"x"+quality.resY+"->"+v.resX+"x"+v.resY);
	}
	
	return v;
}
 
Example 33
Project: Endoscope   File: VideoQuality.java   Source Code and License 6 votes vote down vote up
/** 
 * Checks if the requested resolution is supported by the camera.
 * If not, it modifies it by supported parameters. 
 **/
public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
	VideoQuality v = quality.clone();
	int minDist = Integer.MAX_VALUE;
	String supportedSizesStr = "Supported resolutions: ";
	List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
	for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
		Size size = it.next();
		supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
		int dist = Math.abs(quality.resX - size.width);
		if (dist<minDist) {
			minDist = dist;
			v.resX = size.width;
			v.resY = size.height;
		}
	}
	Log.v(TAG, supportedSizesStr);
	if (quality.resX != v.resX || quality.resY != v.resY) {
		Log.v(TAG,"Resolution modified: "+quality.resX+"x"+quality.resY+"->"+v.resX+"x"+v.resY);
	}
	
	return v;
}
 
Example 34
Project: Rocket.Chat-android   File: CameraManager.java   Source Code and License 6 votes vote down vote up
public void setupCameraAndStartPreview(SurfaceHolder sf, Size sz, int displayRotation) {
	stopCameraPreview();
	
	cameraRotationDegree = CameraHelper.setCameraDisplayOrientation(defaultCameraID, camera, displayRotation);

	chooseCamcorderProfile(sz);

	// tweak profile
	profile.fileFormat = MediaRecorder.OutputFormat.THREE_GPP;
	profile.audioSampleRate = 16000;
	profile.audioChannels = 1;
	profile.audioBitRate = 96000;

	Parameters param = camera.getParameters();

	param.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
	param.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
       if (Build.VERSION.SDK_INT >= 14)
           param.setRecordingHint(true);
	camera.setParameters(param);
	
	if (setDisplay(sf)) {
		startCameraPreview();
	}	
}
 
Example 35
Project: Rocket.Chat-android   File: CameraManager.java   Source Code and License 6 votes vote down vote up
private void chooseCamcorderProfile(Size sizeHint) {
	// For android 2.3 devices video quality = low
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
		profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
	else {
		// For >= Android 3.0 devices select 720p, 480p or low quality of video
		if (CamcorderProfile.hasProfile(getCameraID(), CamcorderProfile.QUALITY_720P)
				&& (sizeHint == null || sizeHint.height >= 720)) {
			profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_720P));
			return;
		}

		if (CamcorderProfile.hasProfile(getCameraID(), CamcorderProfile.QUALITY_480P)
				&& (sizeHint == null || sizeHint.height >= 480)) {
			profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
			return;
		}

		profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
	}
}
 
Example 36
Project: RemoteEye   File: VideoQuality.java   Source Code and License 6 votes vote down vote up
/** 
 * Checks if the requested resolution is supported by the camera.
 * If not, it modifies it by supported parameters. 
 **/
public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
	VideoQuality v = quality.clone();
	int minDist = Integer.MAX_VALUE;
	String supportedSizesStr = "Supported resolutions: ";
	List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
	for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
		Size size = it.next();
		supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
		int dist = Math.abs(quality.resX - size.width);
		if (dist<minDist) {
			minDist = dist;
			v.resX = size.width;
			v.resY = size.height;
		}
	}
	Log.v(TAG, supportedSizesStr);
	if (quality.resX != v.resX || quality.resY != v.resY) {
		Log.v(TAG,"Resolution modified: "+quality.resX+"x"+quality.resY+"->"+v.resX+"x"+v.resY);
	}
	
	return v;
}
 
Example 37
Project: AndroidQrCodeScanner   File: MainActivity.java   Source Code and License 6 votes vote down vote up
public void onPreviewFrame(byte[] data, Camera camera) {
    Parameters parameters = camera.getParameters();
    Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = scanner.scanImage(barcode);
    
    if (result != 0) {
        previewing = false;
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();
        
        SymbolSet syms = scanner.getResults();
        for (Symbol sym : syms) {
          //  scanText.setText("barcode result " + sym.getData());
            Toast.makeText(MainActivity.this,sym.getData(),Toast.LENGTH_SHORT).show();
            barcodeScanned = false;
            mCamera.setPreviewCallback(previewCb);
            mCamera.startPreview();
          //  previewing = true;
            mCamera.autoFocus(autoFocusCB);
        }
    }
}
 
Example 38
Project: pause-resume-video-recording   File: CameraCaptureActivity.java   Source Code and License 6 votes vote down vote up
private Size determineBestSize(List<Size> sizes, int widthThreshold) {
    Size bestSize = null;
    Size size;
    int numOfSizes = sizes.size();
    for (int i = 0; i < numOfSizes; i++) {
        size = sizes.get(i);
        boolean isDesireRatio = (size.width / 4) == (size.height / 3);
        boolean isBetterSize = (bestSize == null) || size.width > bestSize.width;

        if (isDesireRatio && isBetterSize) {
            bestSize = size;
        }
    }

    if (bestSize == null) {
        Log.d(TAG, "cannot find the best camera size");
        return sizes.get(sizes.size() - 1);
    }

    return bestSize;
}
 
Example 39
Project: libstreaming_android_studio   File: VideoQuality.java   Source Code and License 6 votes vote down vote up
/** 
 * Checks if the requested resolution is supported by the camera.
 * If not, it modifies it by supported parameters. 
 **/
public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
	VideoQuality v = quality.clone();
	int minDist = Integer.MAX_VALUE;
	String supportedSizesStr = "Supported resolutions: ";
	List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
	for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
		Size size = it.next();
		supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
		int dist = Math.abs(quality.resX - size.width);
		if (dist<minDist) {
			minDist = dist;
			v.resX = size.width;
			v.resY = size.height;
		}
	}
	Log.v(TAG, supportedSizesStr);
	if (quality.resX != v.resX || quality.resY != v.resY) {
		Log.v(TAG,"Resolution modified: "+quality.resX+"x"+quality.resY+"->"+v.resX+"x"+v.resY);
	}
	
	return v;
}
 
Example 40
Project: DeviceConnect-Android   File: Preview.java   Source Code and License 6 votes vote down vote up
/**
 * カメラのインスタンスを切り替えます.
 *
 * @param cameraId カメラID
 * @param camera 切り替えるカメラのインスタンス
 */
public void switchCamera(final int cameraId, final Camera camera) {
    setCamera(cameraId, camera);
    try {
        camera.setPreviewDisplay(mHolder);
    } catch (IOException exception) {
        if (DEBUG) {
            Log.e(LOG_TAG, "IOException caused by setPreviewDisplay()", exception);
        }
    }
    Camera.Parameters parameters = camera.getParameters();
    if (mPreviewSize != null) {
        parameters.setPreviewSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
    } else {
        Size size = parameters.getPreviewSize();
        mPreviewSize = new HostDeviceRecorder.PictureSize(size.width, size.height);
    }
    requestLayout();

    camera.setParameters(parameters);
}
 
Example 41
Project: WiCamera3D   File: CameraView.java   Source Code and License 6 votes vote down vote up
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
	Camera.Parameters parameters = mCamera.getParameters();

	List<Size> sizes = parameters.getSupportedPreviewSizes();
	Size optimalSize = getOptimalPreviewSize(sizes, w, h);
	parameters.setPreviewSize(640, 480);
	String s = String.format("surface w: %d  h: %d", w, h);
	mScreenWidth = w;
	mScreenHeight = h;
	Log.i("info", s);

	// 创建用于预览合成的图片
	mbmp_previewL = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);// 创建bitmap对象
	mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

	// mCamera.setParameters(parameters);
	mCamera.startPreview();

}
 
Example 42
Project: WiCamera3D   File: WiCameraActivity.java   Source Code and License 6 votes vote down vote up
/**
* 设置全景最佳拍摄参数
* @param supportedSizes
* @param need4To3
* @param needSmaller
* @return
*/
private boolean findBestPreviewSize(List<Size> supportedSizes,
		boolean need4To3, boolean needSmaller) {
	int pixelsDiff = DEFAULT_CAPTURE_PIXELS;
	boolean hasFound = false;
	for (Size size : supportedSizes) {
		int h = size.height;
		int w = size.width;
		// we only want 4:3 format.
		int d = DEFAULT_CAPTURE_PIXELS - h * w;
		if (needSmaller && d < 0) { // no bigger preview than 960x720.
			continue;
		}
		if (need4To3 && (h * 4 != w * 3)) {
			continue;
		}
		d = Math.abs(d);
		if (d < pixelsDiff) {
			mPreviewWidth = w;
			mPreviewHeight = h;
			pixelsDiff = d;
			hasFound = true;
		}
	}
	return hasFound;
}
 
Example 43
Project: batatas-android   File: QRBarcodeReadActivity.java   Source Code and License 6 votes vote down vote up
public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = scanner.scanImage(barcode);

    if (result != 0) {
        previewing = false;
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();

        SymbolSet syms = scanner.getResults();
        for (Symbol sym : syms) {
            String info = sym.getData();
            Intent returnIntent = new Intent();
            returnIntent.putExtra("result", info);
            setResult(RESULT_OK, returnIntent);
            finish();
        }
    }
}
 
Example 44
Project: deface   File: MySurfaceView.java   Source Code and License 6 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {

	parameters = camera.getParameters();// 获取相机参数集

	parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
	List<Size> SupportedPreviewSizes = parameters
			.getSupportedPreviewSizes();// 获取支持预览照片的尺寸
	Size previewSize = SupportedPreviewSizes.get(0);// 从List取出Size
	parameters.setPreviewSize(previewSize.width, previewSize.height);// 设置预览照片的大小
	List<Size> supportedPictureSizes = parameters
			.getSupportedPictureSizes();// 获取支持保存图片的尺寸
	Size pictureSize = supportedPictureSizes.get(0);// 从List取出Size
	parameters.setPictureSize(pictureSize.width, pictureSize.height);// 设置照片的大小
	camera.setParameters(parameters);

	// maxZoom = parameters.getMaxZoom();// 获取最大像素
	// zoomSet.setMax(maxZoom);// 设置最大像素

	try {
		camera.setPreviewDisplay(surfaceHolder);
		camera.startPreview();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 45
Project: prayer-times-android   File: CameraSurfaceView.java   Source Code and License 6 votes vote down vote up
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    if (mCamera == null) {
        return;
    }
    // Now that the size is known, set up the camera parameters and begin
    // the preview.

    Camera.Parameters parameters = mCamera.getParameters();
    Size size = getBestPreviewSize(width, height, parameters);
    if (size != null) {
        parameters.setPreviewSize(size.width, size.height);
    }
    mCamera.setParameters(parameters);

    try {
        mCamera.startPreview();
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
}
 
Example 46
Project: prayer-times-android   File: CameraSurfaceView.java   Source Code and License 6 votes vote down vote up
@Nullable
private Camera.Size getBestPreviewSize(int width, int height, @NonNull Camera.Parameters parameters) {
    Camera.Size result = null;
    double aspect = width / (double) height;
    for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
        if ((size.width >= width) && (size.height >= height)) {
            if (result == null) {
                result = size;
            } else {
                if (Math.abs((result.width / (double) result.height - aspect))
                        > Math.abs((size.width / (double) size.height - aspect))) {
                    result = size;
                }
            }
        }
    }

    return result;
}
 
Example 47
Project: MyCamera   File: CameraUtils.java   Source Code and License 6 votes vote down vote up
public static Camera.Size getSmallestPictureSize(Camera.Parameters parameters) {
  Camera.Size result=null;

  for (Camera.Size size : parameters.getSupportedPictureSizes()) {
    if (result == null) {
      result=size;
    }
    else {
      int resultArea=result.width * result.height;
      int newArea=size.width * size.height;

      if (newArea < resultArea) {
        result=size;
      }
    }
  }

  return(result);
}
 
Example 48
Project: android-sdk-samples   File: CameraHelper.java   Source Code and License 6 votes vote down vote up
private void setupPreviewWithCallbackBuffers() {
    // calculate the size for the callback buffers
    Camera.Parameters params = cameraWrapper.camera.getParameters();
    int previewFormat = params.getPreviewFormat();
    int bitsPerPixel = ImageFormat.getBitsPerPixel(previewFormat);
    Size size = params.getPreviewSize();

    int bufSize = size.width * size.height * bitsPerPixel / 8;

    // add two buffers to the queue, so the camera can be working with one, while the callback is working with the
    // other. The callback will put each buffer it receives back into the buffer queue when it's done, so the
    // camera can use it again.
    cameraWrapper.camera.addCallbackBuffer(new byte[bufSize]);
    cameraWrapper.camera.addCallbackBuffer(new byte[bufSize]);

    cameraWrapper.camera.setPreviewCallbackWithBuffer(this);
}
 
Example 49
Project: android-sdk-samples   File: CameraHelper.java   Source Code and License 6 votes vote down vote up
private void setOptimalPreviewSize(Camera.Parameters cameraParams, int targetWidth, int targetHeight) {
    List<Size> supportedPreviewSizes = cameraParams.getSupportedPreviewSizes();
    // according to Android bug #6271, the emulator sometimes returns null from getSupportedPreviewSizes,
    // although this shouldn't happen on a real device.
    // See https://code.google.com/p/android/issues/detail?id=6271
    if (null == supportedPreviewSizes) {
        Log.v(LOG_TAG, "Camera returning null for getSupportedPreviewSizes(), will use default");
        return;
    }

    Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;

    for (Size size : supportedPreviewSizes) {
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }
    cameraParams.setPreviewSize(optimalSize.width, optimalSize.height);
}
 
Example 50
Project: android-sdk-samples   File: CameraHelper.java   Source Code and License 6 votes vote down vote up
private void setupPreviewWithCallbackBuffers() {
    // calculate the size for the callback buffers
    Camera.Parameters params = safeCamera.getParameters();
    int previewFormat = params.getPreviewFormat();
    int bitsPerPixel = ImageFormat.getBitsPerPixel(previewFormat);
    Size size = params.getPreviewSize();

    int bufSize = size.width * size.height * bitsPerPixel / 8;

    // add two buffers to the queue, so the camera can be working with one, while the callback is working with the
    // other. The callback will put each buffer it receives back into the buffer queue when it's done, so the
    // camera can use it again.
    safeCamera.addCallbackBuffer(new byte[bufSize]);
    safeCamera.addCallbackBuffer(new byte[bufSize]);

    safeCamera.setPreviewCallbackWithBuffer(cameraPreviewer);
}
 
Example 51
Project: javacv   File: FacePreview.java   Source Code and License 6 votes vote down vote up
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    // Now that the size is known, set up the camera parameters and begin
    // the preview.
    Camera.Parameters parameters = mCamera.getParameters();

    List<Size> sizes = parameters.getSupportedPreviewSizes();
    Size optimalSize = getOptimalPreviewSize(sizes, w, h);
    parameters.setPreviewSize(optimalSize.width, optimalSize.height);

    mCamera.setParameters(parameters);
    if (previewCallback != null) {
        mCamera.setPreviewCallbackWithBuffer(previewCallback);
        Camera.Size size = parameters.getPreviewSize();
        byte[] data = new byte[size.width*size.height*
                ImageFormat.getBitsPerPixel(parameters.getPreviewFormat())/8];
        mCamera.addCallbackBuffer(data);
    }
    mCamera.startPreview();
}
 
Example 52
Project: PanBox   File: AssistentActivity.java   Source Code and License 6 votes vote down vote up
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
	// Now that the size is known, set up the camera parameters and begin
	// the preview.
	Camera.Parameters parameters = mCamera.getParameters();

	List<Size> sizes = parameters.getSupportedPreviewSizes();
	Size optimalSize = getOptimalPreviewSize(sizes, w, h);
	//parameters.setPreviewSize(optimalSize.width, optimalSize.height);
	parameters.setPreviewSize(optimalSize.width, optimalSize.height);

	mCamera.setParameters(parameters);
	if (previewCallback != null) {
		mCamera.setPreviewCallbackWithBuffer(previewCallback);
		Camera.Size size = parameters.getPreviewSize();
		byte[] data = new byte[size.width
				* size.height
				* ImageFormat
						.getBitsPerPixel(parameters.getPreviewFormat()) / 8];
		mCamera.addCallbackBuffer(data);
	}
	mCamera.startPreview();
}
 
Example 53
Project: nexus-camera   File: WideAnglePanoramaModule.java   Source Code and License 6 votes vote down vote up
private boolean findBestPreviewSize(List<Size> supportedSizes, boolean need4To3,
        boolean needSmaller) {
    int pixelsDiff = DEFAULT_CAPTURE_PIXELS;
    boolean hasFound = false;
    for (Size size : supportedSizes) {
        int h = size.height;
        int w = size.width;
        // we only want 4:3 format.
        int d = DEFAULT_CAPTURE_PIXELS - h * w;
        if (needSmaller && d < 0) { // no bigger preview than 960x720.
            continue;
        }
        if (need4To3 && (h * 4 != w * 3)) {
            continue;
        }
        d = Math.abs(d);
        if (d < pixelsDiff) {
            mCameraPreviewWidth = w;
            mCameraPreviewHeight = h;
            pixelsDiff = d;
            hasFound = true;
        }
    }
    return hasFound;
}
 
Example 54
Project: nexus-camera   File: CameraSettings.java   Source Code and License 6 votes vote down vote up
public static void initialCameraPictureSize(
        Context context, Parameters parameters) {
    // When launching the camera app first time, we will set the picture
    // size to the first one in the list defined in "arrays.xml" and is also
    // supported by the driver.
    List<Size> supported = parameters.getSupportedPictureSizes();
    if (supported == null) return;
    for (String candidate : context.getResources().getStringArray(
            R.array.pref_camera_picturesize_entryvalues)) {
        if (setCameraPictureSize(candidate, supported, parameters)) {
            SharedPreferences.Editor editor = ComboPreferences
                    .get(context).edit();
            editor.putString(KEY_PICTURE_SIZE, candidate);
            editor.apply();
            return;
        }
    }
    Log.e(TAG, "No supported picture size found");
}
 
Example 55
Project: binea_project_for_android   File: CameraUtils.java   Source Code and License 6 votes vote down vote up
public static Camera.Size getSmallestPictureSize(Camera.Parameters parameters) {
  Camera.Size result=null;

  for (Camera.Size size : parameters.getSupportedPictureSizes()) {
    if (result == null) {
      result=size;
    }
    else {
      int resultArea=result.width * result.height;
      int newArea=size.width * size.height;

      if (newArea < resultArea) {
        result=size;
      }
    }
  }

  return(result);
}
 
Example 56
Project: FourierFilterCam   File: FourierCamActivity.java   Source Code and License 6 votes vote down vote up
public void onCameraViewStarted(int width, int height) {

        mResolutionList = mOpenCvCameraView.getResolutionList();
        mResolutionListString = new String[mResolutionList.size()];
        filterListSpinner.setVisibility(mOpenCvCameraView.INVISIBLE);

        ListIterator<Size> resolutionItr = mResolutionList.listIterator();
        int idx = 0;
        while (resolutionItr.hasNext()) {
            Size element = resolutionItr.next();
            mResolutionListString[idx] = Integer.valueOf(element.width).toString() + "x" + Integer.valueOf(element.height).toString();
            idx++;
        }
        resolutionValue = idx-2;
        // Set default resolution
        Size resolution = mResolutionList.get(resolutionValue);
        mOpenCvCameraView.setResolution(resolution);
        changeVariableSizes();

        filterListSpinner.setVisibility(View.GONE);

        Toast.makeText(this, "Touch screen to take a picture", Toast.LENGTH_SHORT).show();
    }
 
Example 57
Project: OoDroid2   File: VideoQuality.java   Source Code and License 6 votes vote down vote up
/** 
 * Checks if the requested resolution is supported by the camera.
 * If not, it modifies it by supported parameters. 
 **/
public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
	VideoQuality v = quality.clone();
	int minDist = Integer.MAX_VALUE;
	String supportedSizesStr = "Supported resolutions: ";
	List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
	for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
		Size size = it.next();
		supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
		int dist = Math.abs(quality.resX - size.width);
		if (dist<minDist) {
			minDist = dist;
			v.resX = size.width;
			v.resY = size.height;
		}
	}
	Log.v(TAG, supportedSizesStr);
	if (quality.resX != v.resX || quality.resY != v.resY) {
		Log.v(TAG,"Resolution modified: "+quality.resX+"x"+quality.resY+"->"+v.resX+"x"+v.resY);
	}
	
	return v;
}
 
Example 58
Project: Zom-Android   File: CameraView.java   Source Code and License 6 votes vote down vote up
private void startPreview(SurfaceHolder holder) {
	try {

		Parameters params = camera.getParameters();

		if (params.getSupportedFocusModes().contains(
				Camera.Parameters.FOCUS_MODE_AUTO)) {
			params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
		}

		List<Size> previewSizes = camera.getParameters().getSupportedPreviewSizes();
		List<Size> pictureSizes = camera.getParameters().getSupportedPictureSizes();

           params.setPreviewSize(previewSizes.get(previewSizes.size()-2).width,previewSizes.get(previewSizes.size()-2).height);
		params.setPictureSize(pictureSizes.get(pictureSizes.size()-2).width,pictureSizes.get(pictureSizes.size()-2).height);
		camera.setParameters(params);

		camera.setPreviewDisplay(holder);
		camera.startPreview();

		previewConsumer.start(camera);
	} catch(IOException e) {
		Log.e(TAG, "Error starting camera preview", e);
	}
}
 
Example 59
Project: FaceRecognition   File: CamParaUtil.java   Source Code and License 5 votes vote down vote up
public boolean equalRate(Size s, float rate){
	float r = (float)(s.width)/(float)(s.height);
	if(Math.abs(r - rate) <= 0.03)
	{
		return true;
	}
	else{
		return false;
	}
}
 
Example 60
Project: FaceRecognition   File: CamParaUtil.java   Source Code and License 5 votes vote down vote up
public int compare(Size lhs, Size rhs) {
	// TODO Auto-generated method stub
	if(lhs.width == rhs.width){
		return 0;
	}
	else if(lhs.width > rhs.width){
		return 1;
	}
	else{
		return -1;
	}
}