改变imageview的像素颜色

时间:2014-09-08 15:37:15

标签: android

我必须从图库中更改所选图像的一个像素的颜色 我用一个按钮来改变这个像素,但是当我点击按钮时,应用程序总是被迫停止 PLZ帮我解决了这个问题:( 这是我的按钮代码

public void btnClick2 (View v){
     bmp.setPixel(30,30,0xFF000000 );
}

这是onactivityresult代码

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECTED_PICTURE && resultCode == RESULT_OK && null != data)
{
    Uri selectedImage = data.getData();
    String[] filePathColumn = { MediaStore.Images.Media.DATA };

    Cursor cursor = getContentResolver().query(selectedImage,
            filePathColumn, null, null, null);
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();


  bmp = BitmapFactory.decodeFile(picturePath);



  iv1.setImageBitmap(bmp);


}

}

1 个答案:

答案 0 :(得分:1)

它确实强制关闭,因为BitmapFactory.decodeFile返回不可变Bitmap,而setPixel仅适用于可变位图。您可以使用Bitmap.copy获取原始位图的可变版本。

编辑:

Bitmap tmpBmp = BitmapFactory.decodeFile(picturePath);
bmp = tmpBmp.copy(Bitmap.Config.ARGB_8888 ,true);
相关问题