我正在尝试创建一个向图像添加文本的应用程序。在此我的图像来自画廊,文本由用户添加。为此,我创建了我的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/myImageView"
android:layout_alignLeft="@+id/myImageView"
android:layout_alignRight="@+id/myImageView"
android:layout_alignTop="@+id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
活动如下:
public class AddText extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.add_text);
findViewById(R.id.relativelayout).setDrawingCacheEnabled(true);
Bitmap finalImg = findViewById(R.id.relativelayout).getDrawingCache();
String save_location = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/texted";
File dir = new File(save_location);
if (!dir.exists())
dir.mkdirs();
File f = new File(dir, "tmp.jpg");
FileOutputStream out;
try {
out = new FileOutputStream(f);
finalImg.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
现在我想用文本保存整个图像。用文字保存图像的方法是什么?
错误是: