title: How to Draw Portion of Bitmap via Canvas DrawBitmap
body: <p>I have an<br>
   <a href="https://i.stack.imgur.com/KyjP0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KyjP0.png" alt="source condition"></a>:  </p>
  
  <ol>
  <li>FrameLayout(marked with red)  </li>
  <li>Source ImageView(black)  </li>
  <li>Object(imageview) with OnTouchListener (orange) </li>
  </ol>
  
  <p>Via <strong>Object</strong> with OnTouchListener,i want to show a portion of bitmap,that are filled on imageview(<strong>source imageview</strong>).  </p>
  
  <p>So it's not a problem,i'm doing like this:<br>
  <code>Bitmap bt = Bitmap.createBitmap(sourceBitmap,event.getX(),event.getY(),250,250);</code>   </p>
  
  <p><strong>where</strong>:   </p>
  
  <ol>
  <li><strong>SourceBitmap</strong> - is an image that are added to source ImageView  </li>
  <li><strong>event.getX()</strong> / <strong>event.getY()</strong> is an coord,where i start to draw portion of bitmap  </li>
  <li><strong>250</strong>,<strong>250</strong> - its an size of portion bitmap(part).  </li>
  </ol>
  
  <p>and the result is:  </p>
  
  <p><a href="https://i.stack.imgur.com/VTpFV.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/VTpFV.jpg" alt="result of first case"></a></p>
  
  <p>So the problems occurs,when my object(with touchlistener),going to the border(i have made this possibility for <strong>orange</strong> object,to go <strong>out</strong> of border with Object.width()/2).  </p>
  
  <p>So in this case:<br>
  <a href="https://i.stack.imgur.com/HOB11.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HOB11.png" alt="case #2"></a><br>
  how can i achieve this result:<br>
  <a href="https://i.stack.imgur.com/yXqCu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yXqCu.png" alt="excepted result of case #2"></a><br>
  where result of portion will be:  </p>
  
  <ol>
  <li>Part of bitmap  </li>
  <li>second part is color of framelayout background.</li>
  </ol>
  
  <p>What i tried at current moment:  </p>
  
  <pre><code>public boolean onTouch(View view, MotionEvent event) {
  
      switch (event.getAction()) {
          case MotionEvent.ACTION_MOVE:
  
              //i want to draw bigger portion then corrds
              int CurrentX = (int)view.getX() - (view.getWidth());
              int CurrentY = (int)view.getY() - (view.getHeight());
  
              //case,when object is going out of border
              if(CurrentX &lt;= 0)
              {
                  Paint paint = new Paint();
                  paint.setStyle( Style.FILL  );
                  paint.setColor( Color.RED );
  
                  mBitmap = Bitmap.CreateBitmap(sourceBitmap,(int)view.getX() + Math.abs(CurrentX),(int)view.getY(),250,250);
                  Canvas canvas = new Canvas(mBitmap);
                  canvas.drawBitmap(mBitmap,new Rect((int)view.getX()+Math.abs(CurrentX), (int)view.getY(),250-Math.abs(CurrentX),250),new RectF(Math.abs(CurrentX), 0, 250,250),paint);
              }
              break;
      }
  
      return true;
  }
  }
  </code></pre>
  
  <p>Any suggestions? Thanks!</p>