我想使用Line绘制特定的RectangleBitmapCanvas。如果我在位图上绘制,它也会采用方形的空背景。

所以我只想在那个特定的Bitmap区域上绘制。

最佳答案

从您的期望图像中创建一个带有“ bmp1”名称的位图
创建一个自定义视图
创建一个类并像这样扩展View

class MyCustomView extends View{

private Rect m_ImageRect;
private Rect m_TextRect ;

//you need these constructor
//you can init paint object or anything on them
public MyCustomView (Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
    m_Context = context;

}

public MyCustomView (Context context, AttributeSet attrs)
{
    super(context, attrs);
    m_Context = context;

}

public MyCustomView (Context context)
{
    super(context);
    m_Context = context;

}

//then override on draw method
@Override
protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
            //here frist create two rectangle
            //one for your image and two for text you want draw on it
    m_ImageRect = canvas.getClipBounds();
        m_TextRect = canvas.getClipBounds();
            //it gives you an area that can draw on it,
            //the width and height of your rect depend on your screen size device
            canvas.drawBitmap(your bitmap(bmp1), null, m_ImageRect , paint);
            canvas.save();
    canvas.clipRect(m_TextRect);

            canvas.drawText("your text", the x position you want to start draw,
            the y position you want to start draw, m_paintText);

            canvas.restore();
}
}


最后,将自定义视图放在布局上,并在其上设置字段以发送值以查看以绘制所需的所有内容

如果这不是您想要的,希望对您有所帮助!
发布您的代码,以便也许我可以为您提供更多帮助

关于android - 在Android中的特定区域上绘画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17545252/

10-10 06:30