选择图片就不说了
说说混乱图片的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);}
说说混乱图片的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);}
ImageView imageView = (ImageView) findViewById(R.id.iv01);
/* 将Bitmap设定到ImageView * /
imageView.setImageBitmap(bitmap); 是这种,那么如何将imageView 和void suffleImageRGB(Bitmap bmp) 联系到?
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;
}
}
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
各位请帮忙