こんにちは!Android。本当に大きなイメージ(ビットマップ)にテキストを書き込んで保存する方法
次の問題があります。かなり大きなイメージに長いテキストを書いてそこに保存する必要があります。
条件:
- 画像サイズ2000×3000を超えます。
- 画像を部分に分割することは許可されていません。これは、画像がエッジからエッジに書き込まれるためです。
- 追加:元の画像にテキストを書き込む必要があるため、ビットマップスケールまたはマトリックススケールは使用できません。
- を追加しました:私はビットマップのスケールを使用して、ユーザーに画像を表示する場合:メモリの不足と
options.inSampleSize = 10;
と何の問題
現在の問題:
私がしようビットマップエラーでこのイメージをロードすると、メモリの制限(VMバジェット)が発生します。
質問:
- メモリにロードすることなく、大きな画像の上にテキストにどのように?
- これのための既存のライブラリはありますか?
コード例:
// Step 1. Open image and load to Bitmap
Bitmap bitmap = BitmapFactory.decodeFile(fileName); // runtime Exception like "VM budget" !
// or
//Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.big_img_1); // as in previous runtime Exception like "VM budget" !
// or
//Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream); // as in previous runtime Exception like "VM budget" !
// Step 2. Write text
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(14);
Canvas canvas = new Canvas(bitmap);
canvas.drawText("some long long string over all image", 100, 100, paint);
// Step 3. Save bitmap to file
OutputStream fOut = new FileOutputStream(new File(fileName));
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
/*
_________________________________________________
| |
| |
| |
| |
| IMG |
| |
| |
| some long long string over all image |
|________________________________________________|
*/
画像が透明部分を持っているかどうか? – Plato
透明使用していません – Andrei
これに何か不運? – Adrian