我想找个地方 Textiew
我的图片和保存它,但我不知道如何插入文本到图片。
我可以在我的图片上附加一个图像保存它,它可以工作,但现在我想插入一个 Textiew
进入画面。
这是我的密码:
PictureCallback cameraPictureCallbackJpeg = new PictureCallback()
{
@Override
public void onPictureTaken(byte[] data, Camera camera)
{
// TODO Auto-generated method stub
Bitmap cameraBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
wid = cameraBitmap.getWidth();
hgt = cameraBitmap.getHeight();
Bitmap newImage = Bitmap.createBitmap(wid, hgt, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newImage);
canvas.drawBitmap(cameraBitmap, 0f, 0f, null);
Drawable drawable = getResources().getDrawable(R.drawable.love);
drawable.setBounds(20, 20, 260, 160);
drawable.draw(canvas);
File storagePath = new File(Environment.getExternalStorageDirectory() + "/MyPicture/");
storagePath.mkdirs();
File myImage = new File(storagePath,Long.toString(System.currentTimeMillis()) + ".jpg");
try
{
FileOutputStream out = new FileOutputStream(myImage);
newImage.compress(Bitmap.CompressFormat.JPEG, 80, out);
out.flush();
out.close();
}
catch(FileNotFoundException e)
{
Log.d("In Saving File", e + "");
}
catch(IOException e)
{
Log.d("In Saving File", e + "");
}
camera.startPreview();
drawable = null;
newImage.recycle();
newImage = null;
cameraBitmap.recycle();
cameraBitmap = null;
}
;
};
1条答案
按热度按时间anhgbhbe1#
如果你只想要“文本”,而不一定是
TextView
,可以使用直接在画布上绘制文本drawText()
.把它改成:
如果你想成为一个
TextView
当然,您可以将视图转换为位图,然后使用drawBitmap()
. 有关如何转换的示例,请参见此答案。