选择图片就不说了
说说混乱图片的RGB
void suffleImageRGB(Bitmap bmp) {
     int w = bmp.getWidth();
     int h = bmp.getHeight();
     int color=0,r=0,g=0,b=0;
     for(int x=0; x<w; x++){
          for(int y=0 ;y<h; y++){
             color = bmp.getPixel(x, y);
             r = Color.red(color);
             g = Color.green(color);
             b = Color.blue(color);
             bmp.setPixel(x,y,Color.argb(Color.alpha(color), b,g ,r ) );//R->G->B->R
        }
    }}//成员变量
Bitmap bmp ;
//选择了图片后调用
void imgSelected(String imgPath) {
     bmp = BitmapFactory.decodeFile (imgPath);}
//在Button的点击事件里
public void onClick(View v){
     if(bmp==null || bmp.isRecycled() ) return;//
     suffleImageRGB(bmp);}

解决方案 »

  1.   

    谢谢您的回复能否贴上选择图片的代码,因为我的代码是在本地取得图片之后 Bitmap bitmap = BitmapFactory.decodeStream((InputStream) cr.openInputStream(uri));  
                         ImageView imageView = (ImageView) findViewById(R.id.iv01);  
                         /* 将Bitmap设定到ImageView * /  
                         imageView.setImageBitmap(bitmap); 是这种,那么如何将imageView 和void suffleImageRGB(Bitmap bmp)  联系到?
      

  2.   

    下面贴整个我写的代码,请各位帮忙看下哪里写的不对package com.example.gsbtest;import java.io.FileNotFoundException;
    import java.io.InputStream;import android.net.Uri;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Color;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;public class MainActivity extends Activity { Button btn0;
    Button btn1;
    TextView Text1;
    Bitmap bmp, bitmap ;//选择了图片后调用    @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            btn0 = (Button)findViewById(R.id.b01);
            btn0.setText("select image");
            btn1 = (Button)findViewById(R.id.sufflebtn);
            
            btn0.setOnClickListener(new OnClickListener(){
            
             public void onClick(View v){
             Intent intent = new Intent();
             intent.setType("image/*");
             intent.setAction(Intent.ACTION_GET_CONTENT);
             startActivityForResult(intent,1);
             }
            });
            
            btn1.setOnClickListener(new OnClickListener(){
           
             @Override
    public void onClick(View arg0) {
    // TODO Auto-generated method stub
             if(bitmap==null || bitmap.isRecycled() ) //return
             {
             Text1 = (TextView)findViewById(R.id.Txt1);
             Text1.setText("image not found");
             }
             suffleImageRGB(bitmap);
    }
            });
            
        }    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
        {  
            if (resultCode == RESULT_OK) {  
                Uri uri = data.getData();  
                Log.e("uri", uri.toString());  
                android.content.ContentResolver cr = this.getContentResolver();  
                try {  
                    bitmap = BitmapFactory.decodeStream((InputStream) cr.openInputStream(uri));  
                    ImageView imageView = (ImageView) findViewById(R.id.iv01);  
                    /* 将Bitmap设定到ImageView */  
                    imageView.setImageBitmap(bitmap);  
                } catch (FileNotFoundException e) {  
                    Log.e("Exception", e.getMessage(),e);  
                }  
            }  
            super.onActivityResult(requestCode, resultCode, data);  
        }  
        
        void suffleImageRGB(Bitmap bmp) 
        {     
         int w = bmp.getWidth();     
         int h = bmp.getHeight();     
         int color=0,r=0,g=0,b=0;     
         for(int x=0; x<w; x++)
         {          
         for(int y=0 ;y<h; y++)
         {             
         color = bmp.getPixel(x, y);             
         r = Color.red(color);             
         g = Color.green(color);             
         b = Color.blue(color);             
         bmp.setPixel(x,y,Color.argb(Color.alpha(color), b,g ,r ) );//R->G->B->R        }    }   } 
         }
         }
        }
            @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        
    }
      

  3.   

    当点击btn1按钮去运行  suffleImageRGB(bitmap); 的时候提示Unfortunately, app has been stopped,于是给suffleImageRGB函数包了一个try去抓异常,结果出现java.lang.illegalStateException
      

  4.   

    我用try catch 套住 suffleImageRGB(bitmap);,然后运行的时候日志文件里提示如下
     
    04-10 02:54:40.629: D/gralloc_goldfish(792): Emulator without GPU emulation detected.
     04-10 02:56:26.300: E/uri(792): content://media/external/images/media/18
     04-10 02:56:26.660: D/dalvikvm(792): GC_FOR_ALLOC freed 80K, 8% free 2741K/2948K, paused 204ms, total 234ms
     04-10 02:56:26.709: I/dalvikvm-heap(792): Grow heap (frag case) to 3.961MB for 1228816-byte allocation
     04-10 02:56:26.890: D/dalvikvm(792): GC_FOR_ALLOC freed 4K, 6% free 3937K/4152K, paused 136ms, total 136ms
     04-10 02:56:32.230: E/Exception(792): null
     04-10 02:56:32.230: E/Exception(792): java.lang.IllegalStateException
     
    各位请帮忙