I've written the java for image processing working on android. I try to build the method to average color in specific area of image. I found some same warning that i really don't know how to solve it. For example, the warnings tell me that "The value of the local variable "red" is not used", so in the first i solved by declare the int red at the top, but it can't fix. The "red","green","blue","xImage","yImage" are all the same. In addition, the TextView show zero in every variable.
and if i put return red << 16 | green << 8 | blue; the warning is lost, but TextView is still show zero.
Here is the java code. help me please T^T.
import java.io.File;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ImageView;
import android.widget.TextView;
public class ProcessPic extends Activity {
int xImage,yImage,red,green,blue;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_process);
String path = Environment.getExternalStorageDirectory()+ "/TestProcess/picture.jpg";
File imgFile = new File(path);
Bitmap myBitmapPic = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.my_image);
myImage.setImageBitmap(myBitmapPic);
ProcessPic test = new ProcessPic();
test.AverageColor(myBitmapPic, 0, 200, 0, 200);
TextView tv1 = (TextView)findViewById(R.id.textView1);
TextView tv2 = (TextView)findViewById(R.id.textView2);
TextView tv3 = (TextView)findViewById(R.id.textView3);
TextView tv4 = (TextView)findViewById(R.id.textView4);
TextView tv5 = (TextView)findViewById(R.id.textView5);
tv1.setText(Integer.toString(xImage));
tv2.setText(Integer.toString(yImage));
tv3.setText(Integer.toString(red));
tv4.setText(Integer.toString(green));
tv5.setText(Integer.toString(blue));
}
public void AverageColor (Bitmap myBitmap,int minw, int maxw,int minh, int maxh){
int xImage = myBitmap.getWidth();
int yImage = myBitmap.getHeight();
int red = 0;
int green = 0;
int blue = 0;
int count = 0;
for (int i=minw;i<maxw;i++){
for (int j=minh;j<maxh;j++){
int pixel = myBitmap.getPixel(i,j);
red += pixel >> 16 & 0xFF;
green += pixel >> 8 & 0xFF;
blue += pixel & 0xFF;
count++;
}
}
red /= count;
green /= count;
blue /= count;
//return red << 16 | green << 8 | blue;
}
}