Android application development of simple, atmospheric music player to achieve the album Reflection effect _android

Source: Internet
Author: User
Tags reflection

Today to achieve the function is to achieve the album Reflection effect, this function is already part of the image processing, the image processing I am not very good, and so on will introduce a very practical tool class, specially used for image processing. This tool class is not written by me, I just use it to my own project, which is enough, I have achieved the perfect effect I want.

Effect Chart:

<

A very useful tool class

/simplebeautymusicplayer/src/com/wwj/sb/utils/imageutil.java

Package com.wwj.sb.utils; 
Import Java.io.ByteArrayOutputStream; 
Import Java.io.File; 
Import java.io.FileNotFoundException; 
Import Java.io.FileOutputStream; 
Import java.io.IOException; 
Import Android.content.Context; 
Import Android.graphics.Bitmap; 
Import Android.graphics.Bitmap.CompressFormat; 
Import Android.graphics.Bitmap.Config; 
Import Android.graphics.BitmapFactory; 
Import Android.graphics.Canvas; 
Import Android.graphics.ColorMatrix; 
Import Android.graphics.ColorMatrixColorFilter; 
Import android.graphics.LinearGradient; 
Import Android.graphics.Matrix; 
Import Android.graphics.Paint; 
Import Android.graphics.PorterDuff; 
Import Android.graphics.PorterDuff.Mode; 
Import Android.graphics.PorterDuffXfermode; 
Import Android.graphics.Rect; 
Import Android.graphics.RectF; 
Import Android.graphics.Shader; 
Import android.graphics.drawable.BitmapDrawable; 
Import android.graphics.drawable.Drawable; 
/** * Picture Tool class * @author WWJ * 2013/7/3/public class Imageutil {  /** picture of eight positions **/public static final int top = 0;     On public static final int BOTTOM = 1;      Next public static final int left = 2;     Left public static final int right = 3;    Right public static final int left_top = 4;  On the left, public static final int left_bottom = 5;   Lower left public static final int right_top = 6;  On the right, public static final int right_bottom = 7; Lower right/** * Image Amplification Method * @param src Source Bitmap Object * @param scaleX width proportional coefficient * @param scaleY height proportional coefficient * @retur N Returns a Bitmap object */public static Bitmap Zoombitmap (Bitmap src, float scaleX, float scaleY) {Matrix matrix = new Matr 
    IX (); 
    Matrix.setscale (ScaleX, ScaleY); 
    Bitmap t_bitmap = bitmap.createbitmap (src, 0, 0, src.getwidth (), Src.getheight (), Matrix, True); 
  return t_bitmap; /** * Image Zoom Out--@param src * @param width and Height * @param height * @return/Public stat IC Bitmap zoombimtap (Bitmap src, int width, int height) {return Bitmap.createscaledbitmap (src, width, height, true); /** * Convert drawable to Bitmap object * @param drawable * @return/public static Bitmap Drawabletobitmap (Dra 
  Wable drawable) {return (bitmapdrawable) drawable). Getbitmap (); /** * Converts bitmap to drawable object * @param bitmap * @return/public static drawable bitmaptodrawable (Bi 
    TMap bitmap) {drawable drawable = new bitmapdrawable (bitmap); 
  return drawable; /** * Bitmap to byte[] * @param bitmap * @return/public static byte[] Bitmaptobyte (bitmap bitmap) 
    {Bytearrayoutputstream out = new Bytearrayoutputstream (); 
    Bitmap.compress (Bitmap.CompressFormat.PNG, out); 
  return Out.tobytearray (); 
    /** * byte[] Turn Bitmap * @param data * @return/public static Bitmap Bytetobitmap (byte[] data) { 
    if (data.length!= 0) {return bitmapfactory.decodebytearray (data, 0, data.length); 
  return null; 
} 
  /**   * Draw fillet image * @param src * @param radius * @return/public static Bitmap Createroundedcornerbitmap ( 
    Bitmap src, int radius) {Final int w = src.getwidth (); 
    Final int h = src.getheight (); 
    HD 32-bit figure Bitmap Bitmap = Bitmap.createbitmap (W, H, config.argb_8888); 
    Paint Paint = new Paint (); 
    Canvas Canvas = new Canvas (bitmap); 
    Canvas.drawargb (0, 0, 0, 0); 
    Paint.setcolor (0xff424242); 
    Prevent jagged Paint.setfilterbitmap (true) of edges; 
    Rect Rect = new Rect (0, 0, W, h); 
    RECTF RECTF = new RECTF (rect); 
    Draw rectangular canvas.drawroundrect with rounded corners (RECTF, radius, radius, paint); 
    Draw the intersection of two layers to show the upper Paint.setxfermode (new Porterduffxfermode (PorterDuff.Mode.SRC_IN)); 
    Draw Image Canvas.drawbitmap (src, rect, rect, paint); 
  return bitmap; /** * Create check with hint picture * @param context * @param srcid * @param tipid * @return/public static Drawable Createselectedtip (context, int srcid, int tipId) {Bitmap src = bitmapfactory.decoderesource (context.getresources (), srcid); 
    Bitmap tip = Bitmapfactory.decoderesource (Context.getresources (), tipid); 
    Final int w = src.getwidth (); 
    Final int h = src.getheight (); 
    Bitmap Bitmap = Bitmap.createbitmap (W, H, config.argb_8888); 
    Paint Paint = new Paint (); 
    Canvas Canvas = new Canvas (bitmap); 
    Draw Original Canvas.drawbitmap (src, 0, 0, paint); 
    Draw hint picture Canvas.drawbitmap (Tip, (W-tip.getwidth ()), 0, paint); 
  Return bitmaptodrawable (bitmap); 
    /** * Image with Reflection * @param src * @return/public static Bitmap Createreflectionbitmap (Bitmap src) { 
    Space between two images final int spacing = 4; 
    Final int w = src.getwidth (); 
    Final int h = src.getheight (); 
    Draw high quality 32-bit figure Bitmap Bitmap = Bitmap.createbitmap (W, H + h/2 + spacing, config.argb_8888); 
    Create the inverted image matrix M = new matrix () of the Yan X axis; 
    M.setscale (1,-1); Bitmap T_bitmap = Bitmap.createbitmap (SRC, 0, H/2, W, H/2, M, true); 
    Canvas Canvas = new Canvas (bitmap); 
    Paint Paint = new Paint (); 
    Draw the original image Canvas.drawbitmap (src, 0, 0, paint); 
    Draw Reflection Image Canvas.drawbitmap (T_bitmap, 0, H + spacing, paint); Linear rendering-high to low rendering along y-axis Shader Shader = new LinearGradient (0, H + spacing, 0, H + spacing + h/2, 0x70ffffff, 0X00FFFFFF, S Hader. 
    TILEMODE.MIRROR); 
    Paint.setshader (shader); 
    Draw the intersection of two layers to show the lower level. 
    Paint.setxfermode (New Porterduffxfermode (mode.dst_in)); 
    Draw the rectangular canvas.drawrect rendering the reflection (0, H + spacing, W, H + h/2 + spacing, paint); 
  return bitmap; /** * Independent Reflection image * @param src * @return/public static Bitmap Createreflectionbitmapforsingle (Bitma 
    P src) {final int w = src.getwidth (); 
    Final int h = src.getheight (); 
    Draw high quality 32-bit figure Bitmap Bitmap = Bitmap.createbitmap (W, H/2, config.argb_8888); 
    Creates the matrix M = new matrix () of the reflection image along the x-axis; 
    M.setscale (1,-1); Bitmap T_bitmap = BitmAp.createbitmap (src, 0, H/2, W, H/2, M, true); 
    Canvas Canvas = new Canvas (bitmap); 
    Paint Paint = new Paint (); 
    Draw Reflection Images Canvas.drawbitmap (t_bitmap, 0, 0, paint); Linear rendering-high to low rendering along y-axis Shader Shader = new LinearGradient (0, 0, 0, H/2, 0X70FFFFFF, 0X00FFFFFF, Shader.tilemod 
    E.MIRROR); 
    Paint.setshader (shader); Draws the intersection of two layers. 
    Shows the lower level. 
    Paint.setxfermode (New Porterduffxfermode (mode.dst_in)); 
    Draw the rectangular canvas.drawrect (0, 0, W, H/2, paint) rendering the reflection; 
  return bitmap; 
    public static Bitmap Creategreybitmap (Bitmap src) {final int w = src.getwidth (); 
    Final int h = src.getheight (); 
    Bitmap Bitmap = Bitmap.createbitmap (W, H, config.argb_8888); 
    Canvas Canvas = new Canvas (bitmap); 
    Paint Paint = new Paint (); 
    ColorMatrix matrix = new ColorMatrix () for color transformation; 
    Saturation saturation value, the minimum can be set to 0, at this time the corresponding gray-scale map, 1 for the saturation is unchanged, set greater than 1, the display of Supersaturation matrix.setsaturation (0); Colormatrixcolorfilter filter = new ColormatrixcolOrfilter (matrix); 
    Paint.setcolorfilter (filter); 
    Canvas.drawbitmap (SRC, 0, 0, paint); 
  return bitmap; /** * Save picture * @param src * @param filepath * @param FORMAT:[BITMAP.COMPRESSFORMAT.PNG,BITMAP.COMPRESSF Ormat. JPEG] * @return */public static Boolean saveimage (Bitmap src, String filepath, compressformat format) {b 
    Oolean rs = false; 
    File File = new file (filepath); 
      try {fileoutputstream out = new FileOutputStream (file);  if (src.compress (format, out)) {Out.flush (); 
    Write stream} out.close (); 
    catch (FileNotFoundException e) {e.printstacktrace (); 
    catch (IOException e) {e.printstacktrace (); 
  } return RS; 
   /** * Add watermark Effect * @param src source bitmap * @param watermark Watermark * @param direction direction * @param spacing spacing 
    * @return */public static Bitmap Createwatermark (Bitmap src, Bitmap watermark, int direction, int spacing) { FinAl int w = src.getwidth (); 
    Final int h = src.getheight (); 
    Bitmap Bitmap = Bitmap.createbitmap (W, H, config.argb_8888); 
    Canvas Canvas = new Canvas (bitmap); 
    Canvas.drawbitmap (SRC, 0, 0, NULL); 
    if (direction = = Left_top) {canvas.drawbitmap (watermark, spacing, spacing, null); else if (direction = = Left_bottom) {canvas.drawbitmap (watermark, spacing, h-watermark.getheight ()-Spacing, nul 
    L); else if (direction = = Right_top) {canvas.drawbitmap (watermark, W-watermark.getwidth ()-spacing, spacing, null) 
    ; else if (direction = = Right_bottom) {canvas.drawbitmap (watermark, W-watermark.getwidth ()-Spacing, H-waterma 
    Rk.getheight ()-spacing, NULL); 
  return bitmap; /** * Composite image * @param direction * @param bitmaps * @return/public static Bitmap Composebitmap (int direction, Bitmap ... bitmaps) 
    {if (Bitmaps.length < 2) {return null; } Bitmap Firstbitmap =Bitmaps[0]; 
    for (int i = 0; i < bitmaps.length i++) {firstbitmap = Composebitmap (Firstbitmap, bitmaps[i], direction); 
  return firstbitmap; /** * Synthesized two images * @param firstbitmap * @param secondbitmap * @param direction * @return * * PR Ivate static Bitmap Composebitmap (Bitmap firstbitmap, Bitmap secondbitmap, int direction) {if (Firstbitmap = = 
    NULL) {return null; 
    } if (Secondbitmap = = null) {return firstbitmap; 
    Final int fw = Firstbitmap.getwidth (); 
    Final int fh = Firstbitmap.getheight (); 
    Final int sw = Secondbitmap.getwidth (); 
    final int sh = secondbitmap.getheight (); 
    Bitmap Bitmap = null; 
    Canvas Canvas = null; 
      if (direction = top) {bitmap = Bitmap.createbitmap (sw > FW? SW:FW, FH + sh, config.argb_8888); 
      Canvas = new canvas (bitmap); 
      Canvas.drawbitmap (secondbitmap, 0, 0, NULL); Canvas.drawbitmap (firstbitmap, 0, SH, null); 
      else if (direction = = BOTTOM) {bitmap = Bitmap.createbitmap (fw > SW FW:SW, FH + sh, config.argb_8888); 
      Canvas = new canvas (bitmap); 
      Canvas.drawbitmap (firstbitmap, 0, 0, NULL); 
    Canvas.drawbitmap (secondbitmap, 0, FH, NULL); 
      else if (direction = left) {bitmap = Bitmap.createbitmap (fw + SW, sh > FH? sh:fh, config.argb_8888); 
      Canvas = new canvas (bitmap); 
      Canvas.drawbitmap (secondbitmap, 0, 0, NULL); 
    Canvas.drawbitmap (Firstbitmap, SW, 0, NULL); else if (direction = right) {bitmap = Bitmap.createbitmap (fw + SW, FH > SH? fh:sh, Config.argb_ 
      8888); 
      Canvas = new canvas (bitmap); 
      Canvas.drawbitmap (firstbitmap, 0, 0, NULL); 
    Canvas.drawbitmap (Secondbitmap, FW, 0, NULL); 
  return bitmap; } 
}

The embodiment of the music player program in the simple and atmosphere

I have defined a method, the album reflected the effect of the perfect realization.

/** 
   * Show album cover 
   / 
  private void Showartwork (Mp3info mp3info) { 
    Bitmap BM = Mediautil.getartwork (This, Mp3info.getid (), Mp3info.getalbumid (), True, false); 
    Toggle Play Time album photo appears transparent effect 
    Animation Albumanim = animationutils.loadanimation (Playeractivity.this, R.anim.album_ Replace); 
    Start playing animation effect 
    musicalbum.startanimation (Albumanim); 
    if (BM!= null) { 
      musicalbum.setimagebitmap (BM);//Show album cover picture 
      Musicablumreflection.setimagebitmap ( Imageutil.createreflectionbitmapforsingle (BM)); Show Reflection 
    } else { 
      BM = Mediautil.getdefaultartwork (this, false); 
      Musicalbum.setimagebitmap (BM); Show album cover picture 
      Musicablumreflection.setimagebitmap (Imageutil.createreflectionbitmapforsingle (BM));//Show Reflection 
    } 
  

The above content is the Android application development simple, the atmospheric music player realizes the album Reflection effect all tutorials, hoped everybody likes.

Related Article

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.