0

このコード スニペットを約 25 のデバイスでテストしましたが、現在テストしようとしている Samsung Galaxy Nexus を除くすべてのデバイスでうまく機能します。

これがメソッドであり、例外をスローしている正確な場所を見つけるためにそれをトリミングしなかったことをお詫びしますが、Eclipseのデバッグは面倒です.

private void setupImageView() {
    imageLocation = currentPhotoPath;


    // Get the dimensions of the View
    Display display = getWindowManager().getDefaultDisplay();
    Point size = getDisplaySize(display);
    int targetW = size.x;

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;

    BitmapFactory.decodeFile(imageLocation, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetW);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(imageLocation, bmOptions);
    //int rotationForImage = getRotationForImage(imageLocation);
    int rotationForImage = (whichCamera == 0 ? 90 : 270);
    if (rotationForImage != 0) {
        int targetWidth = rotationForImage == 90 || rotationForImage == 270 ? bitmap.getHeight() : bitmap.getWidth();
        int targetHeight = rotationForImage == 90 || rotationForImage == 270 ? bitmap.getWidth() : bitmap.getHeight();
        Bitmap rotatedBitmap = Bitmap.createBitmap(targetWidth, targetHeight, bitmap.getConfig());
        Canvas canvas = new Canvas(rotatedBitmap);
        Matrix matrix = new Matrix();
        matrix.setRotate(rotationForImage, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
        canvas.drawBitmap(bitmap, matrix, new Paint());

        bitmap.recycle();
        bitmap = rotatedBitmap;
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
        try
        {
                File f = new File(imageLocation);
                f.createNewFile();
                //write the bytes in file
                FileOutputStream fo = new FileOutputStream(f);
                fo.write(bytes.toByteArray());
                fo.close();
        }
        catch(java.io.IOException e){}
    }
    imageView.setImageBitmap(bitmap);
}

これが例外をスローする原因となるネクサスでSamsungが異なる方法を知っている人はいますか? Galaxy S IIIで問題なく動作します

4

1 に答える 1

0

あなたが言及したifブロックの何かがNPEを投げているように見えます - それが本当のバグです。下流にあり、NPE によってトリガーされる Activity/ResultInfo について心配する必要はありません。行ごとに移動し、null 参照を探します:-)

Eclipse に関しては、残念ながら私はあまり経験がありません。Android の場合、私は個人的に IntelliJ を使用しており、デバッグはうまく機能します。他の Java コード (単純な Hello, World であっても) をデバッグできますか?

于 2012-12-10T22:57:39.643 に答える