android怎么创建图片文件?? 这样得到的是一个Bitmap 啊,怎么通过bitmap生成图片文件?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请用此方法 public boolean compress (Bitmap.CompressFormat format, int quality, OutputStream stream); // Bitmap.CompressFormat.PNG 直接把byte写到文件里就可以了 如果只是生成图片文件的话,FileOutputStream.write(byte[] bytes) 直接写到文件里,把文件后缀名写成.png即可 public void SavePicture() { try { File file = new File("/mnt/sdcard/pictures"); if (!file.exists()) { file.mkdir(); } FileOutputStream fos = new FileOutputStream("/mnt/sdcard/pictures/"+ picName + ".png"); // Bitmap.CompressFormat.PNG tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos); } catch (FileNotFoundException e) { e.printStackTrace(); } }为毛我执行 了这个函数,DDMS 里面啥也没有呢? public void SavePicture() { try { File file = new File("/mnt/sdcard/pictures"); if (!file.exists()) { file.mkdir(); } FileOutputStream fos = new FileOutputStream("/mnt/sdcard/pictures/"+ picName + ".png"); // Bitmap.CompressFormat.PNG tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos); } catch (FileNotFoundException e) { e.printStackTrace(); } }为毛我执行 了这个函数,DDMS 里面啥也没有呢?因为文件你没有创建File file = new File("/mnt/sdcard/pictures/"+ picName + ".png");file.create(); ...file.create();[code=java] public void SavePicture() { try { File file = new File("/mnt/sdcard/" + picName + ".png"); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //为毛我把程序改成这样还是神马都莫有 检查下是否有文件写权限<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>建议楼主使用Environment.getExternalStorageDirectory();获取SDCard根目录,再执行路径、文件相关操作 ...file.create();[code=java] public void SavePicture() { try { File file = new File("/mnt/sdcard/" + picName + ".png"); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //为毛我把程序改成这样还是神马都莫有看看log是什么异常了 public void SavePicture() { try { File file = new File("/mnt/sdcard/hee.txt"); file.createNewFile(); @SuppressWarnings("resource") FileOutputStream fos = new FileOutputStream(file); fos.write("hello android".getBytes()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }把权限设置了,还是没法生成文件也没报什么异常咋回事啊 你都try catch了报什么异常啊public void saveByteArrayToFile(byte[] bytes, String _file) { FileOutputStream os = null; try { File file = new File(_file); int end = _file.lastIndexOf(File.separator); String _filePath = _file.substring(0, end); File filePath = new File(_filePath); if (!filePath.exists()) { filePath.mkdirs(); } file.createNewFile(); os = new FileOutputStream(file); os.write(bytes); } catch (Exception e) { } finally { if (os != null) { try { os.close(); } catch (Exception e) { } } } } 你都try catch了报什么异常啊public void saveByteArrayToFile(byte[] bytes, String _file) { FileOutputStream os = null; try { File file = new File(_file); int end = _file.lastIndexOf(File.separator); String _filePath = _file.substring(0, end); File filePath = new File(_filePath); if (!filePath.exists()) { filePath.mkdirs(); } file.createNewFile(); os = new FileOutputStream(file); os.write(bytes); } catch (Exception e) { } finally { if (os != null) { try { os.close(); } catch (Exception e) { } } } }谢谢!!好人一生平安 adb shell su后为什么不能输入了? vlc编译问题 android google map api 蓝牙高手进!wsock error的问题 哪里有android图像处理方面的讲解或源代码 求帮忙链接SQL 数据库到安卓数据库 怎样查看系统是否禁用悬浮窗 onReceive在待机状态下也可以收消息吗 ReCyclerView的滑动卡顿 无标题 菜鸟Android小问题!急! android获取缩略图是FileNotFound
// Bitmap.CompressFormat.PNG
public void SavePicture() { try {
File file = new File("/mnt/sdcard/pictures");
if (!file.exists()) {
file.mkdir();
}
FileOutputStream fos = new FileOutputStream("/mnt/sdcard/pictures/"+ picName + ".png");
// Bitmap.CompressFormat.PNG
tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}为毛我执行 了这个函数,DDMS 里面啥也没有呢?
public void SavePicture() { try {
File file = new File("/mnt/sdcard/pictures");
if (!file.exists()) {
file.mkdir();
}
FileOutputStream fos = new FileOutputStream("/mnt/sdcard/pictures/"+ picName + ".png");
// Bitmap.CompressFormat.PNG
tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}为毛我执行 了这个函数,DDMS 里面啥也没有呢?因为文件你没有创建
File file = new File("/mnt/sdcard/pictures/"+ picName + ".png");
file.create();
...
file.create();[code=java]
public void SavePicture() { try {
File file = new File("/mnt/sdcard/" + picName + ".png");
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
为毛我把程序改成这样还是神马都莫有
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>建议楼主使用Environment.getExternalStorageDirectory();获取SDCard根目录,再执行路径、文件相关操作
...
file.create();[code=java]
public void SavePicture() { try {
File file = new File("/mnt/sdcard/" + picName + ".png");
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
tempBitMap.compress(Bitmap.CompressFormat.PNG, 100, fos); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
为毛我把程序改成这样还是神马都莫有
看看log是什么异常了
File file = new File("/mnt/sdcard/hee.txt");
file.createNewFile();
@SuppressWarnings("resource")
FileOutputStream fos = new FileOutputStream(file);
fos.write("hello android".getBytes()); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
把权限设置了,还是没法生成文件也没报什么异常咋回事啊
public void saveByteArrayToFile(byte[] bytes, String _file) {
FileOutputStream os = null;
try {
File file = new File(_file);
int end = _file.lastIndexOf(File.separator);
String _filePath = _file.substring(0, end);
File filePath = new File(_filePath);
if (!filePath.exists()) {
filePath.mkdirs();
}
file.createNewFile();
os = new FileOutputStream(file);
os.write(bytes);
} catch (Exception e) {
}
finally {
if (os != null) {
try {
os.close();
} catch (Exception e) {
}
}
}
}
public void saveByteArrayToFile(byte[] bytes, String _file) {
FileOutputStream os = null;
try {
File file = new File(_file);
int end = _file.lastIndexOf(File.separator);
String _filePath = _file.substring(0, end);
File filePath = new File(_filePath);
if (!filePath.exists()) {
filePath.mkdirs();
}
file.createNewFile();
os = new FileOutputStream(file);
os.write(bytes);
} catch (Exception e) {
}
finally {
if (os != null) {
try {
os.close();
} catch (Exception e) {
}
}
}
}
谢谢!!好人一生平安