Bonjour,

Je développe actuellement une application Android permettant de prendre des photos. J'ai un problème lorsque je tente d'obtenir une meilleure qualité des photos.

En effet, lorsque j'utilise ce code, cela fonctionne la photo est de bonne qualité mais je n'utilise pas la qualité optimale de l'appareil photo de mon téléphone.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
 
    if (isPreviewRunning) {
        mCamera.stopPreview();
    }
    Camera.Parameters parameters = mCamera.getParameters();
    mCamera.setParameters(parameters);
    mCamera.startPreview();
    isPreviewRunning = true;
}
http://img689.imageshack.us/i/04042011172937.jpg/


Le problème survient lorsque je tente d'avoir une qualité plus optimale avec ce code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
    final double ASPECT_TOLERANCE = 0.05;
    double targetRatio = (double) w / h;
    if (sizes == null) return null;
 
    Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;
 
    int targetHeight = h;
 
    // Try to find an size match aspect ratio and size
    for (Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }
 
    // Cannot find the one match the aspect ratio, ignore the requirement
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}
 
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.
    if (isPreviewRunning) {
        mCamera.stopPreview();
    }
    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);
    mCamera.startPreview();
    isPreviewRunning =true;
}
L'image est alors déformée.

http://img97.imageshack.us/i/04042011173220.jpg/

Comment puis je resoudre mon problème?

J'utilise le telphone HTC Desire HD

Cela vient peut être de cette méthode

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PictureCallback mPictureCallbackJpeg = new PictureCallback() {      
            public void onPictureTaken(byte[] imageData, Camera camera) {
    ....
 
    BitmapFactory.Options options=new BitmapFactory.Options();
                            options.inSampleSize = 5; 
                            Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,imageData.length,options);
                            FileOutputStream fOut = new FileOutputStream(path + "/"+fl);
                            BufferedOutputStream bos = new BufferedOutputStream(fOut);
 
 
  myImage.compress(CompressFormat.JPEG, 100, bos);
  bos.flush();
bos.close();
...
Merci d'avance