这样得到的是一个Bitmap 啊,怎么通过bitmap生成图片文件??

解决方案 »

  1.   

    请用此方法 public boolean compress (Bitmap.CompressFormat format, int quality, OutputStream stream); 
    // Bitmap.CompressFormat.PNG
      

  2.   

    直接把byte写到文件里就可以了
      

  3.   

    如果只是生成图片文件的话,FileOutputStream.write(byte[] bytes)
      

  4.   

    直接写到文件里,把文件后缀名写成.png即可
      

  5.   


    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 里面啥也没有呢?
      

  6.   


    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();
      

  7.   


    ...
    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();
    }
    }
    //
    为毛我把程序改成这样还是神马都莫有
      

  8.   

    检查下是否有文件写权限
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>建议楼主使用Environment.getExternalStorageDirectory();获取SDCard根目录,再执行路径、文件相关操作
      

  9.   


    ...
    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是什么异常了
      

  10.   

    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();
    }
    }
    把权限设置了,还是没法生成文件也没报什么异常咋回事啊
      

  11.   

    你都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) {
                        }
                    }
                }
            }
      

  12.   

    你都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) {
                        }
                    }
                }
            }

    谢谢!!好人一生平安