首页 文章

创建一个空位图并在android中绘制画布

提问于
浏览
91

我想创建一个空位图并将canvas设置为该位图,然后在位图上绘制任何形状 .

2 回答

  • -3

    这可能比你想的更简单:

    int w = WIDTH_PX, h = HEIGHT_PX;
    
    Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
    Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
    Canvas canvas = new Canvas(bmp);
    
    // ready to draw on that bitmap through that canvas
    

    在这里找到's a series of tutorials I' ve:Drawing with Canvas Series

  • 177

    不要使用Bitmap.Config.ARGB_8888

    而是使用int w = WIDTH_PX,h = HEIGHT_PX;

    Bitmap.Config conf = Bitmap.Config.ARGB_4444; // see other conf types
    Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
    Canvas canvas = new Canvas(bmp);
    
    // ready to draw on that bitmap through that canvas
    

    处理更多位图或大位图时,ARGB_8888会让您陷入OutOfMemory问题 . 或者更好的是,尝试避免使用ARGB选项本身 .

相关问题