如何在Android中将当前日期的单个图像作为文本和摄像头捕获图像

时间:2012-10-31 09:33:39

标签: android image camera

我正在开发Android应用程序。我的目的是使用设备相机捕获图像,并将当前日期和时间作为文本添加到捕获的图像上。并将整个事物作为单个图像上传到服务器上。

2 个答案:

答案 0 :(得分:1)

阅读here

编辑:

Bitmap photo = (Bitmap) data.getExtras().get("data"); 
//create bitmap with a canvas
Bitmap newPhoto = Bitmap.createBitmap(photo.getWidth(),photo.getHeight());
Canvas canvas = new Canvas(newPhoto);
canvas.drawBitmap(photo,0,0,null);
//draw the text
Paint paint = new Paint();
//paint.setColor(Color.BLACK);
canvas.drawText("write bla bla bla",x,y,paint);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
newPhoto.compress(Bitmap.CompressFormat.PNG, 100, stream);
//get bytes from stream and send to your server

答案 1 :(得分:0)

扩展视图,例如ImageView:

public class MyImageView extends ImageView{}

覆盖onDraw()

@Override
public void onDraw(Canvas canvas){

    // draw the image you got from the camera
    canvas.drawBitmap(cameraImage, 0, 0, paint);

    // draw the date
    canvas.drawText("Date string", x, y, paint);

}

如果您想发送图片:

myImageView.buildDrawingCache();
Bitmap bmp = myImageView.getDrawingCache();

对于发送到服务器,这是另一个问题,这里有很多例子。祝你好运。