【发布时间】:2014-03-20 11:53:41
【问题描述】:
我想将字符串中的一些文本保存为图像。现在我有以下代码:
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) {
}
}
但是,这不会创建位图,而是会引发空指针异常。如何将我的字符串保存到位图?
【问题讨论】:
-
是字符串,位图的代码吗?或者位图应该是一个包含字符串的位图?