这是我要在图像上写的功能 但我的日志显示位图(bmp)为空 并且函数bmp.getwidth()在空对象引用上 任何人都可以请我帮忙,因为我正在使用未缩放的位图
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
File file =new File(Environment.getExternalStorageDirectory()+"/GUI/temp.jpg");
Uri uri=Uri.fromFile(file);
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
try {
if(uri !=null){
Log.d("uri2", "onClick: uri is not null");
bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, bmpFactoryOptions);
if(bmp==null){
Log.d("bitmap", "onClick: bitmap is null");
}
else{
alteredBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp
.getHeight(), bmp.getConfig());
}
bmpFactoryOptions.inJustDecodeBounds = false;
canvas = new Canvas(alteredBitmap);
paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStrokeWidth(5);
matrix = new Matrix();
canvas.drawBitmap(bmp, matrix, paint);
img.setImageBitmap(alteredBitmap);
}else{
Log.d("uri", "onClick: uri is null");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}catch (Exception e){
Log.d("uri", "onClick: uri is null yes"+e.getMessage());
}
}
});