Lumluk Wp
Lumluk Wp

Reputation: 45

Set size of the photo taken by camera

Are there any way to constantly set the resolution of the photo (like 256x256) that were taken by my own camera application. Here is bits of code, Thanks.

SurfaceView cameraView;
SurfaceHolder surfaceHolder;
Camera camera;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    File mFile=new File("/sdcard/Galmix");
    mFile.mkdir();

    cameraView = (SurfaceView)this.findViewById(R.id.CameraView);
    surfaceHolder = cameraView.getHolder();
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    surfaceHolder.addCallback(this);

    cameraView.setFocusable(true);
    cameraView.setFocusableInTouchMode(true);
    cameraView.setClickable(true);

    cameraView.setOnClickListener(this);
}
public void onClick(View v){
    camera.takePicture(null, null, this);
}

@Override
public void onPictureTaken(byte[] data, Camera camera) {
    try{
        OutputStream imageFileOS = new FileOutputStream(String.format("/sdcard/Galmix/%d.jpg",System.currentTimeMillis()));
        imageFileOS.write(data);
        imageFileOS.flush();
        imageFileOS.close();
    } catch(FileNotFoundException e){
        Toast t = Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
        t.show();
    } catch (IOException e) {
        Toast t = Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
        t.show();
    }
    camera.startPreview();
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
    camera.startPreview();
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    try{
        camera.setPreviewDisplay(holder);
        Camera.Parameters parameters = camera.getParameters();

        if(this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE){
            parameters.set("orientation", "portrait");
            camera.setDisplayOrientation(90);   
        }
        List<String> colorEffects = parameters.getSupportedColorEffects();
        Iterator<String> cei = colorEffects.iterator();
        while(cei.hasNext()){
            String currentEffect = cei.next();
            if(currentEffect.equals(Camera.Parameters.EFFECT_SOLARIZE)){
                parameters.setColorEffect(Camera.Parameters.EFFECT_SOLARIZE); break;
            }
        }
        camera.setParameters(parameters);
    } catch(IOException e){
        camera.release();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    camera.stopPreview();
    camera.release();
}

Upvotes: 0

Views: 8754

Answers (2)

Milos Cuculovic
Milos Cuculovic

Reputation: 20223

to resolve your problem, you have to check your camera supported sizes by using this code:

Camera camera = Camera.open();
Parameters params = camera.getParameters();
List<Camera.Size> sizes = params.getSupportedPictureSizes();

Once you will se the supported Sizes, you can define them with the method :

setPictureSize(int width, int height);

Upvotes: 1

Rajath
Rajath

Reputation: 11926

See Camera Parameters for information.

Upvotes: 1

Related Questions