//ファイルに保存
    try {
        byte[] w=bmp2data(bitmap,Bitmap.CompressFormat.JPEG,80);
        writeDataFile("snapshot.jpg",w);
    } catch (Exception e) {
        android.util.Log.e("",e.toString());
    }
  
    //Bitmap→バイトデータ
    static byte[] bmp2data(Bitmap src,
        Bitmap.CompressFormat format,int quality) {
        ByteArrayOutputStream os=new ByteArrayOutputStream();
        src.compress(format,quality,os);
        return os.toByteArray();
    }
    //ファイルへのバイトデータ書き込み
    void writeDataFile(String name,byte[] w) throws Exception {
        OutputStream out=null;
        try {
            out=openFileOutput(name,Context.MODE_WORLD_READABLE);
            out.write(w,0,w.length);
            out.close();
        } catch (Exception e) {
        	e.printStackTrace();
            try {
                if (out!=null) out.close();
            } catch (Exception e2) {

            }

            throw e;
        }
    }
© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha