Skip to content

Instantly share code, notes, and snippets.

View yushaojian13's full-sized avatar

Yu Shaojian yushaojian13

View GitHub Profile
@yushaojian13
yushaojian13 / BitmapUtils.java
Last active August 1, 2019 10:58
A bitmap util that scale source bitmap to specific size with aspect ratio remained, alpha pixels filled on one dimension if need
public class BitmapUtils {
/**
* scale source bitmap to specific width and height remaining the aspect ratio.
* If source bitmap aspect ratio is not the same with target ((float) dstWidth / dstHeight),
* then one dimension will scaled to the target value, and another will be filled with 0 alpha pixels
*
* @param src source bitmap
* @param dstWidth target width
* @param dstHeight target height
@yushaojian13
yushaojian13 / ImageSaveTask.java
Last active July 24, 2020 16:46
A task to download and save image to SD card with Glide
public class ImageSaveTask extends AsyncTask<String, Void, Void> {
private Context context;
public ImageSaveTask(Context context) {
this.context = context;
}
@Override
protected Void doInBackground(String... params) {
if (params == null || params.length < 2) {
public Bitmap blurBitmap(Bitmap bitmap){
//Let's create an empty bitmap with the same size of the bitmap we want to blur
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
//Instantiate a new Renderscript
RenderScript rs = RenderScript.create(getApplicationContext());
//Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));