在 Android 中创建一个空位图并通过画布绘制 [英] Creating an empty bitmap and drawing though canvas in Android

查看:26
本文介绍了在 Android 中创建一个空位图并通过画布绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to create an empty bitmap and set a canvas to that bitmap and then draw any shape on the bitmap.

推荐答案

这可能比你想象的要简单:

This is probably simpler than you're thinking:

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

这是我在该主题上找到的一系列教程:绘图与帆布系列

Here's a series of tutorials I've found on the topic: Drawing with Canvas Series

这篇关于在 Android 中创建一个空位图并通过画布绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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