相关疑难解决方法(0)

在ImageVIew上绘制矩形

我想实现裁剪功能,在该功能上我想在imageView上有一个小矩形。矩形应该是静态的,我想移动图像并在矩形区域内进行裁剪。然后将矩形内的图像作为裁剪后的图像。我尝试使用Bitmap作为参数创建画布,但没有用。我已经做了很多尝试来搜索如何执行此操作。但在任何地方都找不到。请帮忙..

Bitmap bitmap=BitmapFactory.decodeResource(this.getResources(), R.drawable.indoor);

    Bitmap mutBitmap = Bitmap.createBitmap(200, 400,bitmap.getConfig());

    Canvas canvas = new Canvas(mutBitmap);

            Paint paint = new Paint();
            paint.setColor(Color.BLACK);
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
            paint.setStrokeWidth(10);
            float leftx = 20;
            float topy = 20;
            float rightx = 50;
            float bottomy = 100;
            canvas.drawRect(leftx, topy, rightx, bottomy, paint);
Run Code Online (Sandbox Code Playgroud)

我正在使用上面的代码,但是imageView上没有绘制矩形。

java android

3
推荐指数
1
解决办法
9448
查看次数

标签 统计

android ×1

java ×1