gpt4 book ai didi

android - 从 imageview 和 textview 创建图像?

转载 作者:搜寻专家 更新时间:2023-11-01 09:08:12 26 4
gpt4 key购买 nike

我正在制作一个应用程序,允许用户从他们手机的图库中将照片添加到 imageview,我已经能够成功编写代码。我现在希望能够允许用户在照片顶部添加文本,然后将文本和图像作为一个保存回画廊。有什么办法吗?

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>

成员(member).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);
}
}

最佳答案

是的,有办法做到这一点,

您可以使用 buildDrawingCache()getDrawingCache()

创建任何 View 的位图
TextView tv = (TextView)findViewById(R.id.textview);
tv.buildDrawingCache();
ImageView img = (ImageView)findViewById(R.id.imageview);
img.setImageBitmap(tv.getDrawingCache());

您还可以检查this回答以供进一步引用。

关于android - 从 imageview 和 textview 创建图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10333596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com