0

我已经在大约 25 台设备上测试了这个代码片段,除了我现在尝试测试的三星 Galaxy Nexus 之外,它在所有设备上都运行良好。

这是方法,我很抱歉没有将其修剪以找到引发异常的确切位置,但 eclipse 的调试是 doodoo。

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);
}

任何人都知道三星对关系的不同之处会导致抛出异常吗?它在 Galaxy S III 上运行良好

4

1 回答 1

0

看起来您提到的 if 块中的某些内容正在抛出 NPE - 这是真正的错误。不要担心 Activity/ResultInfo 的东西,它是下游的,由 NPE 触发。逐行查找空引用:-)

关于 Eclipse - 遗憾的是我在那里没有太多经验。对于 Android,我个人使用 IntelliJ,调试效果很好。您是否能够调试其他 Java 代码(甚至是简单的 Hello, World)?

于 2012-12-10T22:57:39.643 回答