繁体   English   中英

图像旋转在Samsung Galaxy Nexus android上不起作用

[英]image rotation not working on Samsung Galaxy Nexus android

我已经在大约25种设备上测试了此代码段,并且除了我现在要测试的Samsung 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上运行正常

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM