Reputation: 4633
Friends , when i tried to use the setPixel(x, y, color) in my app , it returns a NullPointerException and stopps working. Here is my code. Please help me to get out of the error. Thanks in advance
decode=(Button)findViewById(R.id.button1);
decode.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
try
{
Bitmap result = BitmapFactory.decodeFile(filePath);
int x=result.getPixel(10, 10);
int pixelAlpha= Color.alpha(x);
int red = 65;// represent character A
int green= Color.green(x);
int blue= Color.blue(x);
int newPixel=Color.argb(pixelAlpha,red,green,blue);
result.setPixel(10, 10, newPixel);
ImageView myNewImage=(ImageView)findViewById(R.id.imageView2);
myNewImage.setImageBitmap(result);
}
catch(Exception exc)
{
Toast.makeText(getBaseContext(), "Exception : "+exc, Toast.LENGTH_LONG).show();
}
}
});
Upvotes: 0
Views: 207
Reputation:
It looks like Bitmap result = BitmapFactory.decodeFile(filePath);
could not properly decode your filePath. Ensure result is not null and your filePath is correct.
Upvotes: 2