Bitmap scaling and shadow effects in android

Source: Internet
Author: User

1. Zoom

/**
* Zoom bitmap to certain size
*
* @ Param bitmap
* @ Param width
* @ Param height
* @ Return
*/
Public static Bitmap zoomBitmap (Bitmap bitmap, int width, int height ){
If (bitmap = null ){
Return null;
}

Int w = bitmap. getWidth ();
Int h = bitmap. getHeight ();
Matrix matrix = new Matrix ();
Float scaleWidth = (float) width/w );
Float scaleHeight = (float) height/h );
Matrix. postScale (scaleWidth, scaleHeight );
Bitmap newbmp = Bitmap. createBitmap (bitmap, 0, 0, w, h, matrix, true );
Return newbmp;
}


2. Shadow
/**

* Add shadow to bitmap
*
* @ Param originalBitmap
* @ Return
*/
Private Bitmap drawImageDropShadow (Bitmap originalBitmap ){

BlurMaskFilter blurFilter = new BlurMaskFilter (1,
BlurMaskFilter. Blur. NORMAL );
Paint shadowPaint = new Paint ();
ShadowPaint. setAlpha (50 );
ShadowPaint. setColor (activity. getResources ()
. GetColor (R. color. solid_red ));
ShadowPaint. setMaskFilter (blurFilter );

Int [] offsetXY = new int [2];
Bitmap shadowBitmap = originalBitmap
. ExtractAlpha (shadowPaint, offsetXY );

Bitmap shadowImage32 = shadowBitmap. copy (Bitmap. Config. ARGB_8888, true );
Canvas c = new Canvas (shadowImage32 );
C. drawBitmap (originalBitmap, offsetXY [0], offsetXY [1], null );

Return shadowImage32;
}

 


From fhy_2008

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.