【问题标题】:Draw on Loaded image on Android在 Android 上绘制加载的图像
【发布时间】: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


    【解决方案1】:

    与其使用 Bitmap.copy,不如尝试通过 createBitmap 创建一个相同大小的新位图,然后将启动器图标绘制到这个新位图上。然后你就可以在上面画画了。

    【讨论】:

      猜你喜欢
      • 2017-07-05
      • 2012-11-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      相关资源
      最近更新 更多