title: Bitmap.getPixel only returning 0
body: <p>I have the following code for creating a bitmap:</p>
  
  <pre><code>public PixelMapper(Path inputPath){
      RectF src = new RectF();
      inputPath.computeBounds(src, true);
      int width = (int)src.width()+1;
      int height = (int)src.height()+1;
      largeBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
  
      Paint canvasPaint = new Paint();
      canvasPaint.setAntiAlias(false);
      canvasPaint.setColor(Color.BLACK);
      canvasPaint.setStyle(Style.STROKE);
      canvasPaint.setStrokeWidth(5);
  
      Canvas canvas = new Canvas(largeBitmap);
      canvas.drawPath(inputPath, canvasPaint);
      bitmap = Bitmap.createScaledBitmap(largeBitmap, SIDE_OF_BITMAP, SIDE_OF_BITMAP, true);
      bitmap = Bitmap.createBitmap(bitmap);//so that a immutable bitmap is created
      drawPixelMap();
  }
  
  public void drawPixelMap(){
      for(int x=0; x&lt;bitmap.getWidth(); x++){
          String msg="";
          for(int y=0; y&lt;bitmap.getHeight(); y++){
              msg = Integer.toHexString( bitmap.getPixel(x,y) );
              Log.v("bitmap", msg);   
          }           
      }
  }
  
  int[] pixels = new int[64]; 
  bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, SIDE_OF_BITMAP, SIDE_OF_BITMAP);
  bitmap.setPixels(pixels, 0, 8, 0, 0, 8, 8);
  for ( int pixel : pixels)
      Log.v("bitmap", Integer.toHexString(pixel) );
  </code></pre>
  
  <p>The problem is that all the log messages are "0": both getPixel and getPixels return "0". What is worse is that if I remove the line <code>bitmap.getPixels(...);</code> and leave the <code>bitmap.setPixels(...)</code> line,the image is still drawn as before. It seems that the <code>bitmap</code> variable is just a reference and a bitmap doesn't exist, and for some reason, I am unable to get those pixels.
  I know the bitmap is created as required as I am able to view it on a <code>ImageView</code>. It shows black and white pixels with a few grey ones too. Code:</p>
  
  <pre><code>Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, 128, 128, false);
  imageView1.setImageBitmap(newBitmap);
  </code></pre>
  
  <p>The <code>SIDE_OF_BITMAP = 8</code>, all classes (Path, Bitmap, Canvas) are of android.</p>
  
  <p>I tried saving the bitmap to file with the following code:</p>
  
  <pre><code>public String saveToStorage(String fileName){
      if( !storageDir.exists() )
          storageDir.mkdirs();
      File file = new File(storageDir, fileName + ".png");
      try{
          OutputStream out = new FileOutputStream(file);
          boolean result = bitmap.compress(CompressFormat.PNG, 100, out);
          out.close();
          return Boolean.toString(result);
      }
      catch (FileNotFoundException e){
          Log.e("save", "cannot save file", e);
          return "File not found exception";
      }
      catch (IOException e){
          Log.e("save", "IO error", e);
          return "IO Exception";
      }
  }
  </code></pre>
  
  <p>but it returns "false" i.e. the bitmap.compress method returns false. Please give me any help at all, not necessarily sample code.</p>