2

ユーザーが自分の携帯電話のギャラリーから画像ビューに写真を追加できるようにするアプリを作成していますが、これは既に正常にコーディングできています。ユーザーが写真の上にテキストを追加し、テキストと画像を 1 つとしてギャラリーに保存できるようにしたいと考えています。これを行う方法はありますか?

XML:

  <LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView android:id="@+id/image" android:layout_height="400dp" android:layout_width="fill_parent"/>
    <LinearLayout 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent" 
        android:orientation="horizontal">
        <Button 
            android:id="@+id/chooseimage" 
            android:layout_height="fill_parent" 
            android:layout_weight="1" 
            android:layout_width="fill_parent" 
            android:text="Choose Image"/>
        <Button 
            android:id="@+id/addtext" 
            android:layout_height="fill_parent" 
            android:layout_weight="1" 
            android:layout_width="fill_parent" 
            android:text="Add Text"/>
        <Button 
            android:id="@+id/save" 
            android:layout_height="fill_parent" 
            android:layout_weight="1" 
            android:layout_width="fill_parent" 
            android:text="Save"/>
    </LinearLayout>
</LinearLayout>  

メンバー.java

public class MemberActivity extends Activity implements OnClickListener {
    /**
     * Called when the activity is first created.
     */

    private static final int SELECT_IMAGE = 1;
    Button openGallery;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.design);
        openGallery = (Button) findViewById(R.id.chooseimage);
        openGallery.setOnClickListener(this);

    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.chooseimage:
                Intent gallery = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                startActivityForResult(gallery, SELECT_IMAGE);
                break;
            default:
                break;
        }
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK && requestCode == SELECT_IMAGE) {
            Uri selectedImage = data.getData();
            String path = getPath(selectedImage);
            Bitmap bitmapImage = BitmapFactory.decodeFile(path);
            ImageView image = (ImageView) findViewById(R.id.image);
            image.setImageBitmap(bitmapImage);
        }
    }

    public String getPath(Uri uri) {
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

        return cursor.getString(columnIndex);
    }
}
4

4 に答える 4

3

はい、これを行う方法があります。

buildDrawingCache()と を使用して、任意のビューのビットマップを作成できます。getDrawingCache()

TextView tv = (TextView)findViewById(R.id.textview);
tv.buildDrawingCache();
ImageView img = (ImageView)findViewById(R.id.imageview);
img.setImageBitmap(tv.getDrawingCache());

さらに参照するために、この回答を確認することもできます。

于 2012-04-26T13:12:19.123 に答える
1
于 2012-04-26T13:02:32.387 に答える
0

これを試して:

 TextView tv1 = new TextView(this);
 LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100);
    tv1.setLayoutParams(layoutParams);
    tv1.setText("testing 1 2 3");
    tv1.setTextColor(Color.BLACK);
    tv1.setBackgroundColor(Color.TRANSPARENT);

レイアウトでボタンをクリックして追加->レイアウト参照、次に

.addview(tv1);

于 2015-03-14T08:27:46.177 に答える
0

ImageView の代わりに TextView を使用し、TextView の背景として画像を設定することもできます。その後、TextView にテキストを追加することもできます。すべてのテキストをどこかに保存し、再びギャラリーを表示すると、画像とともに保存したテキストが再び使用されます。

于 2012-04-26T14:18:31.500 に答える