The image color processing method of Android programming _android

Source: Internet
Author: User

This article illustrates the image color processing method of Android programming. Share to everyone for your reference, specific as follows:

Do you want to be able to handle your own photos and beautify your photos as you do with the beautiful Mito? In fact, you can do one of these software, nonsense not to say, directly on the map, on the code!

The effect chart is as follows:

Not before processing:

After processing:

The code for Mainactivity.java is as follows:

Package net.loonggg.test; 
Import android.app.Activity; 
Import Android.graphics.Bitmap; 
Import Android.graphics.BitmapFactory; 
Import Android.graphics.Canvas; 
Import Android.graphics.Color; 
Import Android.graphics.ColorMatrix; 
Import Android.graphics.ColorMatrixColorFilter; 
Import Android.graphics.Matrix; 
Import Android.graphics.Paint; 
Import Android.os.Bundle; 
Import Android.widget.ImageView; 
Import Android.widget.SeekBar; 
Import Android.widget.SeekBar.OnSeekBarChangeListener; 
  public class Mainactivity extends activity {private SeekBar sb1, SB2, SB3, SB4, SB5; 
  Private ImageView IV; 
  Private Bitmap Bitmap, Updatebitmap; 
  Private Canvas Canvas; 
  Private Paint Paint; 
    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
    Setcontentview (R.layout.activity_main); 
    IV = (ImageView) Findviewbyid (R.ID.IV); 
    SB1 = (SeekBar) Findviewbyid (R.ID.SB1); 
    SB2 = (SeekBar) Findviewbyid (R.ID.SB2); Sb3= (SeekBar) Findviewbyid (R.ID.SB3); 
    SB4 = (SeekBar) Findviewbyid (R.ID.SB4); 
    SB5 = (SeekBar) Findviewbyid (R.ID.SB5); 
    Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.b); 
    Updatebitmap = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.getconfig ()); 
    Canvas = new canvas (UPDATEBITMAP); 
    Paint = new paint (); 
    Final ColorMatrix cm = new ColorMatrix (); 
    Paint.setcolorfilter (new Colormatrixcolorfilter (cm)); 
    Paint.setcolor (Color.Black); 
    Paint.setantialias (TRUE); 
    Final Matrix matrix = new Matrix (); 
    Canvas.drawbitmap (bitmap, matrix, paint); 
    Iv.setimagebitmap (UPDATEBITMAP); 
      /** * RGB Three-color red value setting/Sb1.setonseekbarchangelistener (new Onseekbarchangelistener () {@Override 
        public void Onstoptrackingtouch (SeekBar SeekBar) {int progress = seekbar.getprogress (); Cm.set (new float[] {progress/128f, 0, 0, 0, 0,//red value 0, 1, 0, 0, 0,//Green value 
            0, 0, 1, 0, 0,//blue value 0, 0, 0, 1, 0//transparency}); 
        Paint.setcolorfilter (new Colormatrixcolorfilter (cm)); 
        Canvas.drawbitmap (bitmap, matrix, paint); 
      Iv.setimagebitmap (UPDATEBITMAP);  @Override public void Onstarttrackingtouch (SeekBar SeekBar) {} @Override public void 
    Onprogresschanged (SeekBar SeekBar, int progress, Boolean fromuser) {}}); 
      /** * RGB Three-color green value setting/Sb2.setonseekbarchangelistener (new Onseekbarchangelistener () {@Override 
        public void Onstoptrackingtouch (SeekBar SeekBar) {int progress = seekbar.getprogress (); Cm.set (New float[] {1, 0, 0, 0, 0,//red value 0, progress/128f, 0, 0, 0,//green value 0, 0, 1, 0, 0,//Blue 
        Values 0, 0, 0, 1, 0//transparency}); 
        Paint.setcolorfilter (new Colormatrixcolorfilter (cm)); 
        Canvas.drawbitmap (bitmap, matrix, paint); IV.setimagebitmap (UPDATEBITMAP);  @Override public void Onstarttrackingtouch (SeekBar SeekBar) {} @Override public void 
    Onprogresschanged (SeekBar SeekBar, int progress, Boolean fromuser) {}}); 
      /** * RGB Three primary color blue value setting/Sb3.setonseekbarchangelistener (new Onseekbarchangelistener () {@Override 
        public void Onstoptrackingtouch (SeekBar SeekBar) {int progress = seekbar.getprogress (); Cm.set (New float[] {1, 0, 0, 0, 0,//red value 0, 1, 0, 0, 0,//green value 0, 0, progress/128f, 0, 0,//Blue 
        Values 0, 0, 0, 1, 0//transparency}); 
        Paint.setcolorfilter (new Colormatrixcolorfilter (cm)); 
        Canvas.drawbitmap (bitmap, matrix, paint); 
      Iv.setimagebitmap (UPDATEBITMAP);  @Override public void Onstarttrackingtouch (SeekBar SeekBar) {} @Override public void Onprogresschanged (SeekBar SeekBar, int progrESS, Boolean fromuser) {}}); /** * RGB Three primary Colors three values are changed to set saturation (brightness)/Sb4.setonseekbarchangelistener (new Onseekbarchangelistener () {@O 
        Verride public void Onstoptrackingtouch (SeekBar SeekBar) {int progress = seekbar.getprogress (); Cm.set (new float[] {progress/128f, 0, 0, 0, 0,//red value 0, progress/128f, 0, 0, 0,//green value 0, 0 
        , progress/128f, 0, 0,//blue value 0, 0, 0, 1, 0//transparency}); 
        Paint.setcolorfilter (new Colormatrixcolorfilter (cm)); 
        Canvas.drawbitmap (bitmap, matrix, paint); 
      Iv.setimagebitmap (UPDATEBITMAP);  @Override public void Onstarttrackingtouch (SeekBar SeekBar) {} @Override public void 
    Onprogresschanged (SeekBar SeekBar, int progress, Boolean fromuser) {}}); 
      /** * RGB Three primary Colors set Transparency * * Sb5.setonseekbarchangelistener (new Onseekbarchangelistener () {@Override public void Onstoptrackingtouch (SeekBar SeekBar) {int progress = seekbar.getprogress (); 
            Cm.set (New float[] {1, 0, 0, 0, 0,//red value 0, 1, 0, 0, 0,//green value 0, 0, 1, 0, 0,//blue value 
        0, 0, 0, progress/128f, 0//transparency}); 
        Paint.setcolorfilter (new Colormatrixcolorfilter (cm)); 
        Canvas.drawbitmap (bitmap, matrix, paint); 
      Iv.setimagebitmap (UPDATEBITMAP);  @Override public void Onstarttrackingtouch (SeekBar SeekBar) {} @Override public void 
  Onprogresschanged (SeekBar SeekBar, int progress, Boolean fromuser) {}});

 } 
}

The

Layout file code is as follows:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http:// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "android:backg" Round= "#CDCDCD" android:orientation= "vertical" tools:context= ". Mainactivity "> <imageview android:id=" @+id/iv "android:layout_width=" Fill_parent "Android:layout_" height= "Wrap_content"/> <linearlayout android:layout_width= "Fill_parent" android:layout_height= 
    Ontent "android:gravity=" center_vertical "android:orientation=" horizontal "android:padding=" 10DP "> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content"  
      Red: "android:textcolor=" #FF0000 "android:textsize=" "24sp"/> <seekbar android:id= "@+id/sb1" Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" Android:max= "256" android:progress= "128"/> </LinearLayout> <linearlayout android:layout_width= "f Ill_parent "android:layout_height=" wrap_content "android:gravity=" center_vertical "android:orientation=" hor Izontal "android:padding=" 10DP "> <textview android:layout_width=" wrap_content "Android:layo  
    ut_height= "Wrap_content" android:text= "Green:" android:textcolor= "#00FF00" android:textsize= "24sp"/> <seekbar android:id= "@+id/sb2" android:layout_width= fill_parent "android:layout_height=" Wra 
    P_content "android:max=" 256 "android:progress=" 128 "/> </LinearLayout> <linearlayout Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:gravity= "center_vertical" a ndroid:orientation= "Horizontal" android:padding= "10DP" > <textview android:layout_width= "Wrap_conte" NT "Android:layout_height= "wrap_content" android:text= "Blue:" android:textcolor= "#0000FF" android:textsize= "24sp"/> <seekbar android:id= "@+id/sb3" android:layout_width= fill_parent "android:layout_height=" wrap _content "android:max=" 256 "android:progress=" 128 "/> </LinearLayout> <linearlayout A Ndroid:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:gravity= "Center_vertical" an droid:orientation= "Horizontal" android:padding= "10DP" > <textview android:layout_width= "Wrap_conten" T "android:layout_height=" wrap_content "android:text=" saturation: "android:textcolor=" #000000 "Androi D:textsize= "16.5sp"/> <seekbar android:id= "@+id/sb4" android:layout_width= "Fill_parent" a 
  ndroid:layout_height= "Wrap_content" android:max= "256" android:progress= "128"/> </LinearLayout> 
   <linearlayout Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:gravity= "center_vertical" android:orientation= "Horizontal" android:padding= "10DP" > <textview android:layout_width= "Wrap_cont" Ent "android:layout_height=" wrap_content "android:text=" Transparency: android:textcolor= "#000000" Andr 
      Oid:textsize= "16.5sp"/> <seekbar android:id= "@+id/sb5" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:max= "256" android:progress= "128"/> </linearlayout&gt 
; </LinearLayout>

It's over here, you see?

I hope this article will help you with the Android program.

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.