2011-11-01 118 views
0

我需要放大圖像,我用下面的代碼爲它

int imageId = (Integer) intent.getExtras().get(ProfilePageNormalUser.class.getName()); 
    imageView = (ImageView)findViewById(R.id.imageviewEnlarged); 
    System.out.println("*********"+imageId); 

    InputStream is = this.getResources().openRawResource(imageId); 
    Bitmap originalBitmap = BitmapFactory.decodeStream(is); 
    Matrix imageMatrix = new Matrix(); imageMatrix.postRotate(90); 
    Bitmap scaledBitmap = Bitmap.createBitmap(originalBitmap, imageView.getWidth(), imageView.getHeight(), originalBitmap.getWidth(), originalBitmap.getHeight(), imageMatrix, false); 
    imageView.setImageBitmap(scaledBitmap); 

不過是給我上述的異常。

  Resources$NotFoundException: Resource ID #0x4 

誰能告訴我哪裏可能是問題。 謝謝

回答

1

我想用this.getResources().openRawResource(id)。您必須將資源移至res/raw文件夾。

嘗試在res文件夾下創建一個名爲raw的文件夾並將其粘貼到那裏。

讓我知道如何去..

0

OpenRawResource找不到您使用的imageId的資源。

檢查imageId。

您可以直接使用:我認爲:InputStream ins = getResources().openRawResource(R.raw.my_db_file);

就像從原始文件夾上述指定圖像標識。

先檢查一下,它是否有效。

+0

圖像標識是正確的我已經檢查了 – ekjyot

+0

我在過去的活動明確設置圖像標識,並得到同樣的圖像標識此項活動 – ekjyot

+0

見我的編輯,U可以檢查一次 – Udaykiran

相關問題