3
我想將Textiew
添加到我的圖片並保存,但我不確定如何將圖片插入到圖片中。Android將文字添加到圖片並保存
我可以附加一張圖片在我的圖片保存它,它的工作原理,但現在我想插入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;
}
;
};
我應該在myPaint中放置什麼? – alvin890101
['Paint'](http://developer.android.com/reference/android/graphics/Paint.html)可以讓你定義文本的外觀。對齊方式,顏色,字體等。您可能只需傳遞'null',但我不知道默認的顏色是什麼樣的。我從來沒有用過它的文字。 – Geobits