私のアプリでは、1 つの画面が表示されます。その画面に編集テキスト フィールドを配置し、その編集テキスト フィールドの下に選択ボタンと保存ボタンを使用します。編集テキスト フィールド内にテキストを入力し、その後、カーソルがその場所を指している場所に画像を追加する必要があります。ピックボタンを使用してギャラリーから画像を取得し、画像を編集テキストフィールドに再度入力した後、何かを入力したいと思います。ギャラリーに画像として保存されたテキストフィールドを編集する保存ボタンをクリックしますが、これに関してGoogleで検索したことがありますが、解決策を見つけることができません。
1633 次
1 に答える
1
EditText は View の一種です。そのビューをビットマップに変換し、必要な場所に保存します。そのためのJavaコードは
// capture bitmapt of genreated textview
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache(); // destory drawable
EditText で画像を設定する
SpannableStringBuilder ssb = new SpannableStringBuilder("");
BitmapDrawable bmpDrawable = new BitmapDrawable(viewBmp);
bmpDrawable.setBounds(0, 0,bmpDrawable.getIntrinsicWidth(),bmpDrawable.getIntrinsicHeight());
// create and set imagespan
ssb.setSpan(new ImageSpan(bmpDrawable),x ,x + c.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
edtText.setText(ssb);
于 2014-05-26T04:56:31.637 に答える