android 在canvas画了一张图片在代码中我怎么得到它 20
2个回答
展开全部
参见代码:
///兄局/////////////携空///////////////////羡隐让//////////////////////////////////////;
// Save canvas to file.
// Get the width and height of screen.
DisplayMetrics display = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(display);
int width = display.widthPixels;
int height = display.heightPixels;
// Create bitmap.
Bitmap bt = Bitmap.createBitmap(width, height, Config.ARGB_8888);
// Create canvas.
Canvas canvas = new Canvas();
canvas.setBitmap(bt);
Paint paint = new Paint();
// Draw a oval.
int left = width>>2;
int right = left*3;
int top = height>>2;
int bottom = top*3;
paint.setStyle(Style.STROKE);
canvas.drawOval(new RectF(left,top,right,bottom), paint);
// Draw text.
paint.setTextAlign(Align.CENTER);
paint.setColor(Color.RED);
canvas.drawText("Hi,man!", width>>1, height>>1,paint);
// Save canvas.
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
//Save canvas to file.
File file = new File(getFilesDir(), "hiMan.png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bt.compress(Bitmap.CompressFormat.PNG, 50, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
///兄局/////////////携空///////////////////羡隐让//////////////////////////////////////;
// Save canvas to file.
// Get the width and height of screen.
DisplayMetrics display = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(display);
int width = display.widthPixels;
int height = display.heightPixels;
// Create bitmap.
Bitmap bt = Bitmap.createBitmap(width, height, Config.ARGB_8888);
// Create canvas.
Canvas canvas = new Canvas();
canvas.setBitmap(bt);
Paint paint = new Paint();
// Draw a oval.
int left = width>>2;
int right = left*3;
int top = height>>2;
int bottom = top*3;
paint.setStyle(Style.STROKE);
canvas.drawOval(new RectF(left,top,right,bottom), paint);
// Draw text.
paint.setTextAlign(Align.CENTER);
paint.setColor(Color.RED);
canvas.drawText("Hi,man!", width>>1, height>>1,paint);
// Save canvas.
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
//Save canvas to file.
File file = new File(getFilesDir(), "hiMan.png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bt.compress(Bitmap.CompressFormat.PNG, 50, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
追问
我只是想的得到那张图片, 你怎么搞了这么多?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你使用canvas之后 会生成一个对象 这个对象可以说就是你所需要的图片
追问
我所说的对象就是画布上的图片,我能够对他进行操作!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询