我有一个字符串文本,想将其保存为图片。目前我有以下代码:
private void saveImage(View view){
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + "spacitron.png";
String spacitron = "spacitron";
Bitmap bitmap = BitmapFactory.decodeByteArray(spacitron.getBytes(), 0, spacitron.getBytes().length*5);
OutputStream fout = null;
File imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
//This line throws a null pointer exception
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
然而这并没有创建位图,反而抛出了空指针异常。我该如何将字符串保存到位图中?