0

Can I ask someone to review my code please. Its an android application that looks at pixels in the center of the bitmap and displays the values to the user. The results seems to be inaccurate when i look them up online, often appearing bluish or black. Is something missing from the code ? do i need to do something to the imageview in xml or do you think its to with the phones hardware ? Iv tried on a sony m2 and and a sony mini

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    Bitmap bp = (Bitmap) data.getExtras().get("data");
    imgFavorite.setImageBitmap(bp);
}

public void pix(){
    operation= Bitmap.createBitmap(bmp.getWidth(),
            bmp.getHeight(),bmp.getConfig());

    int height = bmp.getHeight();
    int width = bmp.getWidth();
    int p = bmp.getPixel(height / 2, width / 2);

    int r = Color.red(p);
    int g = Color.green(p);
    int b = Color.blue(p);

    Toast.makeText(this, String.valueOf(r) + String.valueOf(g) + String.valueOf(b), Toast.LENGTH_LONG).show();
}
leo666
  • 27
  • 3
  • What seems inaccurate ? The way the image appears in imgFavorite or the r,g,b values ? – inmyth Apr 18 '15 at 16:16
  • main issue would be the rgb values although the image appearance is a bit off as it fills the imageview on the smaller sony mini but for some reason takes a rectangular shape in the larger sony m2 – leo666 Apr 18 '15 at 16:22

1 Answers1

0

Image may appear differently on various devices or display settings but those pixels should remain the same. So you may try replacing bmp.getConfig() with Bitmap.Config.ARGB_8888 or a couple other configurations from Bitmap.Config. This config determines how pixels are stored and affects color depth.

If your image doesn't fill the ImageView container then it's probably scale issue.

inmyth
  • 8,880
  • 4
  • 47
  • 52