【发布时间】:2016-07-04 17:07:10
【问题描述】:
我使用此代码加载图片
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();
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));`
这是工作并在 imageview 上显示图片不是我想在其上画一个圆圈并保存,我可以使用此代码绘制它
BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither = true;
myOptions.inScaled = false;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
myOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_luncher);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
canvas.drawCircle(60, 50, 25, paint);
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(mutableBitmap);`
但我无法绘制,因为它在位图资源上设置了“ic_luncher”。 所以用户无法在加载的图片上绘制,我应该替换什么代码
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_luncher);?
【问题讨论】:
标签: java android canvas bitmap imageview