added image resize
parent
8df3d45139
commit
53614b3c86
|
|
@ -45,9 +45,9 @@ class ImageGetterAsyncTask(
|
||||||
try {
|
try {
|
||||||
k = URL(source).content as InputStream
|
k = URL(source).content as InputStream
|
||||||
val options = BitmapFactory.Options()
|
val options = BitmapFactory.Options()
|
||||||
options.inSampleSize = 1/4
|
options.inSampleSize = 1
|
||||||
// this makes 1/2 of origin image size from width and height.
|
// Putting 2 makes 1/2 of origin image size from width and height.
|
||||||
// it alleviates the memory for API16-API19 especially
|
// it alleviates the memory and CPU too for weak devices.
|
||||||
pic = BitmapFactory.decodeStream(k, null, options)
|
pic = BitmapFactory.decodeStream(k, null, options)
|
||||||
k.close()
|
k.close()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
|
@ -67,15 +67,14 @@ class ImageGetterAsyncTask(
|
||||||
val size = Point()
|
val size = Point()
|
||||||
(context as Activity).windowManager.defaultDisplay.getSize(size)
|
(context as Activity).windowManager.defaultDisplay.getSize(size)
|
||||||
// Lets calculate the ratio according to the screen width in px
|
// Lets calculate the ratio according to the screen width in px
|
||||||
val multiplier: Int = size.x / bitmap!!.width
|
val multiplier: Double = (size.x).toDouble() / (bitmap!!.width.toDouble())
|
||||||
//Log.d(LOG_CAT, "multiplier: $multiplier")
|
|
||||||
levelListDrawable.addLevel(1, 1, d)
|
levelListDrawable.addLevel(1, 1, d)
|
||||||
// Set bounds width and height according to the bitmap resized size
|
// Set bounds width and height according to the bitmap resized size
|
||||||
levelListDrawable.setBounds(
|
levelListDrawable.setBounds(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
bitmap.width * multiplier,
|
(bitmap.width.toDouble() * multiplier).toInt(),
|
||||||
bitmap.height * multiplier
|
(bitmap.height.toDouble() * multiplier).toInt()
|
||||||
)
|
)
|
||||||
levelListDrawable.level = 1
|
levelListDrawable.level = 1
|
||||||
t!!.text = t!!.text // invalidate() doesn't work correctly...
|
t!!.text = t!!.text // invalidate() doesn't work correctly...
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue