小编Ash*_*man的帖子

Bitmap.createBitmap(Bitmap source,int x,int y,int width,int height)返回错误的位图

我必须裁剪位图图像.为此我正在使用

Bitmap bitmap = Bitmap.createBitmap(imgView.getWidth(),imgView.getHeight(), Bitmap.Config.RGB_565);
Bitmap result =Bitmap.createBitmap(bitmap,imgView.getLeft()+10, imgView.getTop()+50, imgView.getWidth()-20, imgView.getHeight()-100);
bitmap.recycle();
Canvas canvas = new Canvas(result);
imgView.draw(canvas);
Run Code Online (Sandbox Code Playgroud)

但它会切割位图的底部和右侧.位图的顶部和左侧部分存在于输出中.这意味着x和y位置无效.

我搜索了一个很好的文档.但我不能.

提前致谢

这里有什么问题以及如何解决?

android image

7
推荐指数
1
解决办法
4万
查看次数

如何绘制透明内部区域的矩形?

我想在像这个图像的视图的中心绘制矩形.为此,我使用以下代码

public class TransparentView extends View {


    public TransparentView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public TransparentView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TransparentView(Context context) {
        super(context);
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        canvas.drawColor(Color.parseColor("#60000000"));
        Paint borderPaint = new Paint();
        borderPaint.setARGB(255, 255, 128, 0);
        borderPaint.setStyle(Paint.Style.STROKE);
        borderPaint.setStrokeWidth(4);

        Paint innerPaint = new Paint();
        innerPaint.setARGB(0, 0, 0, 0);
        innerPaint.setAlpha(0);
        innerPaint.setStyle(Paint.Style.FILL);

        RectF drawRect = new RectF();

        drawRect.set(100, 100, 100,100);

        canvas.drawRect(drawRect, innerPaint);
        canvas.drawRect(drawRect, borderPaint);

    }

} …
Run Code Online (Sandbox Code Playgroud)

android styles

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

image ×1

styles ×1