diff --git a/app/src/main/kotlin/org/ntlab/leftoverrecipe/util/BitmapUtil.kt b/app/src/main/kotlin/org/ntlab/leftoverrecipe/util/BitmapUtil.kt new file mode 100644 index 0000000..ebeca5b --- /dev/null +++ b/app/src/main/kotlin/org/ntlab/leftoverrecipe/util/BitmapUtil.kt @@ -0,0 +1,22 @@ +package org.ntlab.leftoverrecipe.util + +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import java.io.ByteArrayOutputStream + +/** + * Created by matsumoto_k on 2017/07/09. + */ +class BitmapUtil { + companion object { + + fun createImageByteArray(bitmap: Bitmap): ByteArray { + val baos = ByteArrayOutputStream() + bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos) + val imageByteArray = baos.toByteArray() + return imageByteArray + } + + fun createBitmap(imageByteArray: ByteArray) = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.size) + } +} \ No newline at end of file