在Bitmap上画图,并显示

通过以下代码,可以在一个Activity中画图,也可将其作为Bitmap保存。
int w = 320,h = 240;
String mstrTitle = "Hello, itrats!";
Bitmap mbmpTest = Bitmap.createBitmap(w,h, Config.ARGB_8888);
Canvas canvasTemp = new Canvas(mbmpTest);
canvasTemp.drawColor(Color.YELLOW);
Paint p = new Paint();
p.setAntiAlias(true);
String familyName = "宋体";
Typeface font = Typeface.create(familyName, Typeface.BOLD);
p.setColor(Color.RED);
p.setTypeface(font);
p.setTextSize(22);
canvasTemp.drawLine(0, 0, 150, 150, p);
canvasTemp.drawText(mstrTitle,0,100,p);
        
p.setColor(Color.GREEN);
int rx = 230;
int ry = 170;
int r = 60;
RectF rf = new RectF(rx - r, ry - r, rx + r, ry + r);
canvasTemp.drawArc(rf, 0, -120, true, p);

ImageView iview = (ImageView)findViewById(R.id.iv);
iview.setImageBitmap(mbmpTest);


另外,这里还有几种画图表的方法:
- Java4Less (http://java4less.com/charts/chart.php?info=android)
- Chart4J (http://code.google.com/p/charts4j/)
- BlueChart (http://code.google.com/p/bluechart/)- aChartEngine (http://code.google.com/p/achartengine/)
- aiCharts (http://www.artfulbits.com/Android/aiCharts.aspx)

你可能感兴趣的:(bitmap)