Bitmapをpng画像として保存
Bitmapをpng画像として保存する方法。
public static boolean storeBitmap(Context context, Bitmap bitmap, String fileName) { if (bitmap != null && fileName != null) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); byte[] byteArray = output.toByteArray(); OutputStream outputStream = null; try { outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE); // Execute write outputStream.write(byteArray); return true; } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } } return false; }
上記ではpngとして書いたけど、jpgでもいけるハズ。