I want to make a simple test programm which set the color of the pixel onPress.
My Code:
public class DrawActivity extends Activity {
/** Called when the activity is first created. */
Bitmap bitmap;
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv = (ImageView)findViewById(R.id.imageView1);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
iv.setImageBitmap(bitmap);
iv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
bitmap.setPixel((int)event.getX(), (int)event.getY(), Color.BLUE);
Log.e("DRAW", String.valueOf(event.getX())+" "+String.valueOf(event.getY()));
Log.e("DRAW",String.valueOf(Color.BLUE)+" "+ bitmap.getPixel((int)event.getX(), (int)event.getY()));
iv.setImageBitmap(bitmap);
return false;
}
});
}
}
Log:
03-31 22:56:12.072: E/DRAW(6148): 297.65625 194.0 03-31 22:56:12.091:
E/DRAW(6148): -16776961 -16776961 03-31 22:56:13.341: E/DRAW(6148):
355.3125 315.875 03-31 22:56:13.341: E/DRAW(6148): -16776961 -16776961 03-31 22:56:13.865: E/DRAW(6148): 243.28125 481.5 03-31 22:56:13.865:
E/DRAW(6148): -16776961 -16776961 03-31 22:56:14.248: E/DRAW(6148):
93.28125 511.1875 03-31 22:56:14.248: E/DRAW(6148): -16776961 -16776961 03-31 22:56:14.537: E/DRAW(6148): 35.625 472.125 03-31 22:56:14.537: E/DRAW(6148): -16776961 -16776961
The problem is that the pixel is never blue on touch.
Please help
did you dry setting more than 1 pixel? maybe the pixel is too small and you just don’t see it. also i had a bug once in a listview when i set the divider height to 1px it didn’t show up, when set to 2px the divider appeared.