20 lines
589 B
Kotlin
20 lines
589 B
Kotlin
package com.example.myapplication.model
|
|
|
|
import android.graphics.Bitmap
|
|
import android.graphics.BitmapFactory
|
|
import androidx.room.TypeConverter
|
|
import java.io.ByteArrayOutputStream
|
|
|
|
class Converters {
|
|
@TypeConverter
|
|
fun fromBitmap(bitmap: Bitmap) : ByteArray {
|
|
val outputStream = ByteArrayOutputStream();
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 1, outputStream)
|
|
return outputStream.toByteArray()
|
|
}
|
|
|
|
@TypeConverter
|
|
fun toBitmap(byteArray: ByteArray): Bitmap {
|
|
return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
|
|
}
|
|
} |