small fix

This commit is contained in:
movavi 2023-11-18 12:43:37 +03:00
parent 6fb5b51fb8
commit 938e85d993
3 changed files with 13 additions and 19 deletions

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="RF8T107E6PV" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-10-30T15:01:39.013836900Z" />
</component>
</project>

View File

@ -61,20 +61,22 @@ abstract class AppDatabase : RoomDatabase() {
var image1 = converters.imageResourceToByteArray(appContext, R.drawable.image_bouquet1)
var image2 = converters.imageResourceToByteArray(appContext, R.drawable.image_bouquet2)
val resizedImage1 = converters.resizeByteArrayImage(image1, 300, 300)
val resizedImage2 = converters.resizeByteArrayImage(image2, 300, 300)
val bouquets = listOf(
Bouquet(
1,
"Bouquet1",
5,
3432,
image1,
resizedImage1,
),
Bouquet(
2,
"Bouquet2",
9,
2342,
image2,
resizedImage2,
)
)

View File

@ -35,4 +35,13 @@ class Converters {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
return stream.toByteArray()
}
fun resizeByteArrayImage(imageData: ByteArray, reqWidth: Int, reqHeight: Int): ByteArray {
val originalBitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.size)
val resizedBitmap = Bitmap.createScaledBitmap(originalBitmap, reqWidth, reqHeight, true)
val outputStream = ByteArrayOutputStream()
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
return outputStream.toByteArray()
}
}