title: How to change color of painted bitmaps on canvas?
body: <p>I am new to android and i have an app that does painting on canvas. After painting on canvas i am saving the bitmaps as png format image and it works.</p>
  
  <p>The painting is done using green color but before saving i want to change the color of green painted bitmaps, how to change the color of green to white color. </p>
  
  <p>An example would be like this</p>
  
  <p>On painting : (the image is set as background i.e MyView.setbackgroud(sample.png))</p>
  
  <p><img src="https://i.stack.imgur.com/R6ieV.png" alt="during painting"></p>
  
  <p>On Saving: (the result after saving the image )</p>
  
  <p><img src="https://i.stack.imgur.com/3Q7Q9.png" alt="saved image"></p>
  
  <p>The result that i want is like this which will be saved in png format.</p>
  
  <p><img src="https://i.stack.imgur.com/lJTmk.png" alt="resultant image"></p>
  
  <pre><code>       FileOutputStream ostream = null;
      try
      {
          ostream = new FileOutputStream(file);
  
          System.out.println(ostream);
          View targetView = mv;
  
          // myDrawView.setDrawingCacheEnabled(true);
          //   Bitmap save = Bitmap.createBitmap(myDrawView.getDrawingCache());
          //   myDrawView.setDrawingCacheEnabled(false);
          // copy this bitmap otherwise distroying the cache will destroy
          // the bitmap for the referencing drawable and you'll not
          // get the captured view
          //   Bitmap save = b1.copy(Bitmap.Config.ARGB_8888, false);
          //BitmapDrawable d = new BitmapDrawable(b);
          //canvasView.setBackgroundDrawable(d);
          //   myDrawView.destroyDrawingCache();
          // Bitmap save = myDrawView.getBitmapFromMemCache("0");
          // myDrawView.setDrawingCacheEnabled(true);
          //Bitmap save = myDrawView.getDrawingCache(false);
  
  
  
  
          Bitmap well = mv.mBitmap;
          Bitmap save = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
          Paint paint = new Paint();
          paint.setColor(Color.BLACK);
          //Paint paint2 = new Paint();
         // paint2.setColor(Color.WHITE);
  
          Canvas now = new Canvas(save);
          now.drawRect(new Rect(0,0,320,480), paint);
          now.drawBitmap(well, new Rect(0,0,well.getWidth(),well.getHeight()), new Rect(0,0,320,480),null);
         // now.drawBitmap(well,well.getWidth(),well.getHeight(),paint2);
        //  now.setColorFilter(ContextCompat.getColor(this, R.color.colorBlack));
        //  now.drawBitmap(well,0,paint2,well.getWidth(),well.getHeight());
  
          if(save == null) {
              System.out.println("NULL bitmap save\n");
          }
          save.compress(Bitmap.CompressFormat.PNG, 100, ostream);
          //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream);
          //ostream.flush();
          //ostream.close();
      }catch (NullPointerException e)
      {
          e.printStackTrace();
          Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show();
      }
  
      catch (FileNotFoundException e)
      {
          e.printStackTrace();
          Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show();
      }
  
      catch (IOException e)
      {
          e.printStackTrace();
          Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show();
      }
  </code></pre>