绘制圆的现有图像 [英] Draw a circle on an existing image

查看:185
本文介绍了绘制圆的现有图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一个圆圈里面放置的 RES /绘制/ schoolboard.png 的图像上。图像填满活动的背景。下面不工作:

I'm trying to draw a circle on an image which placed as res/drawable/schoolboard.png. the image fills the activity background. the following does not work:

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.schoolboard);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.BLUE);

    Canvas canvas = new Canvas(bitmap);
    canvas.drawCircle(60, 50, 25, paint);

    ImageView imageView = (ImageView)findViewById(R.drawable.schoolboard);
    imageView.setAdjustViewBounds(true);
    imageView.setImageBitmap(bitmap);

任何帮助将是非常美联社preciated。谢谢。

any help will be highly appreciated. thanks.

推荐答案

有在code一些错误: 第一件事,你不能给refrence ID为绘制在findViewById 所以我觉得你的意思是这样的

there are some errors in your code: first of thing you cannot give refrence Id for drawable in findViewById so I think you mean something like that

的ImageView ImageView的=(ImageView的)findViewById(R.id.schoolboard_image_view);

schoolboard_image_view:在你的XML布局中的图片ID(请检查您的权利ID布局)

schoolboard_image_view: is the image id in your xml layout (check your layout for the right id)

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.schoolboard,myOptions);
    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.schoolboard_image_view);
    imageView.setAdjustViewBounds(true);
    imageView.setImageBitmap(mutableBitmap);

请务必使用正确的图片ID为:

Please make sure to use the right image Id for :

ImageView的ImageView的=(ImageView的)findViewById( R.id.schoolboard_image_view );

ImageView imageView = (ImageView)findViewById(R.id.schoolboard_image_view);

这篇关于绘制圆的现有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆