This repository has been archived by the owner on May 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix gradient icon size, fix dp and px unit
- Loading branch information
Showing
7 changed files
with
86 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
bottomTabView/src/main/java/vip/mystery0/bottomTabView/util/ImageUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package vip.mystery0.bottomTabView.util | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
import android.graphics.Matrix | ||
import android.graphics.drawable.Drawable | ||
import android.graphics.PixelFormat | ||
import android.graphics.drawable.BitmapDrawable | ||
|
||
|
||
object ImageUtil { | ||
fun zoomBitmap(bitmap: Bitmap, width: Float, height: Float): Bitmap { | ||
val oldWidth = bitmap.width | ||
val oldHeight = bitmap.height | ||
val scaleWidth = width / oldWidth.toFloat() | ||
val scaleHeight = height / oldHeight.toFloat() | ||
val matrix = Matrix() | ||
matrix.postScale(scaleWidth, scaleHeight) | ||
return Bitmap.createBitmap(bitmap, 0, 0, oldWidth, oldHeight, matrix, true) | ||
} | ||
|
||
fun zoomDrawable(context: Context, drawable: Drawable, width: Float, height: Float): Drawable { | ||
val bitmap = drawableToBitmap(drawable) | ||
return BitmapDrawable(context.resources, zoomBitmap(bitmap, width, height)) | ||
} | ||
|
||
fun drawableToBitmap(drawable: Drawable): Bitmap { | ||
val width = drawable.intrinsicWidth//取drawable的长宽 | ||
val height = drawable.intrinsicHeight | ||
val config = if (drawable.opacity != PixelFormat.OPAQUE) | ||
Bitmap.Config.ARGB_8888 else Bitmap.Config.RGB_565//取drawable的颜色格式 | ||
val bitmap = Bitmap.createBitmap(width, height, config)//建立对应bitmap | ||
val canvas = Canvas(bitmap)//建立对应bitmap的画布 | ||
drawable.setBounds(0, 0, width, height) | ||
drawable.draw(canvas)//把drawable内容画到画布中 | ||
return bitmap | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters