gpt4 book ai didi

android - 解决textview转位图时黑屏

转载 作者:行者123 更新时间:2023-11-29 19:39:05 25 4
gpt4 key购买 nike

我想将 textView 转换为位图,但我得到的是黑屏而不是 textview 中的数据。

我要转换的屏幕

enter image description here

我在绘制缓存后得到的屏幕

enter image description here

我不知道我哪里错了。

以下是我的代码

abc.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3"
android:paddingBottom="5dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.bgc.activity.AlterQuotes"
tools:showIn="@layout/activity_alter_quotes">

<RelativeLayout
android:id="@+id/AlterQuotesrl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.18">

<TextView
android:id="@+id/AlterQuotestvTestText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="15sp"
android:textColor="#000000"
android:background="@drawable/frame"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/sample_name"/>

</RelativeLayout>

</LinearLayout>

abc.java

RelativeLayout z = (RelativeLayout) findViewById(R.id.AlterQuotesrl);
z.setDrawingCacheEnabled(true);
z.buildDrawingCache();
Bitmap bitmapSetDrawingChache = Bitmap.createBitmap(z.getDrawingCache());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmapSetDrawingChache.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);

// saving in sdcard
File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "Birthday Card" + File.separator);
if(!file.exists())
file.mkdirs();

String imageName = "Image-" + DateFormat.getDateTimeInstance().format(new Date()) + ".jpg";

fileImagePath = new File(file,imageName);
try {
FileOutputStream fileOutputStream = new FileOutputStream(fileImagePath);
fileOutputStream.write(byteArrayOutputStream.toByteArray());
fileOutputStream.close();

AlertDialog.Builder adb = new AlertDialog.Builder(AlterQuotes.this);
adb.setTitle("Alert");
adb.setMessage("You will not be able to change, are you sure you want to continue?");
adb.setIcon(this.getResources().getDrawable(R.drawable.ic_black_alert_two));
adb.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(AlterQuotes.this, CardMaker.class);
intent.putExtra("bitmapPath",fileImagePath.toString());
startActivity(intent);
}
});
adb.show();
} catch (IOException e) {
e.printStackTrace();
}

提前致谢..

最佳答案

透明背景通常会导致转换为位图时背景变黑,请尝试将 TextView 背景框架的背景颜色设置为有点像白色,然后再尝试将其转换为位图。

关于android - 解决textview转位图时黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38850809/

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