Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I were you, I'd use the <code>Canvas.scale(float sx, float sy, float px, float py)</code> method which does exactly what you want.</p> <p>However looking at your code I think you might be messing with too many transformations at once, which is harder to debug.</p> <ol> <li><p>Always (and I mean <em>always</em>) call <code>Canvas.save()</code> and <code>Canvas.restore()</code> on the initial matrix you're getting in <code>Canvas</code> if you plan to alter it. This is because the <code>Canvas</code> that you get to draw on may be the canvas for e.g. the whole window with just clipping set to the boundaries of the control that is currently drawing itself.</p></li> <li><p>Use matrix transformation method provided by the <code>Canvas</code> method and draw bitmap using the simplest invocation.</p></li> </ol> <p>Following these two advices look at the whole <code>View</code> I have just made up, that scales the <code>bitmap</code> by a factor of <code>3</code> with point <code>(16,16)</code> set as the pivot (unchanged point - center of scaling). Tested - working.</p> <pre><code>public class DrawingView extends View { Bitmap bitmap; public DrawingView(Context context) { super(context); bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher); } @Override protected void onDraw(Canvas canvas) { float sx = 3; float sy = 3; float px = 16; float py = 16; canvas.save(); canvas.scale(sx, sy, px, py); canvas.drawBitmap(bitmap, 0, 0, null); canvas.restore(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload