Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Rotation of image around the center
    primarykey
    data
    text
    <p>I'm trying to rotate an image around the center. This works generally using RotateAnimation, but I want to have it a bit faster. I'm now using the SurfaceView pattern with a separate drawing thread.</p> <p>This is code, which draws the bitmap correctly (depending on the outer "heading")</p> <p>heading = angle in degrees, bitmap = the bitmap, w = width of the bitmap, h = height of the bitmap.</p> <pre><code> Matrix m = new Matrix(); m.preRotate(heading, w/2, h/2); m.setTranslate(50,50); canvas.drawBitmap(bitmap, m, null); </code></pre> <p>Drawback: The image is a circle and the code above produces visible aliasing effects...</p> <p>The code below is also rotating the image, but while rotating (say from 0 to 45 degrees clockwise) the center of the new image moves bottom/right. I suppose, the eccentric effect is due to the enlarged width/height of the new image ?? However, this code doesn't produce aliasing, if filter=true is set. Is there a way to use code #1 but have sort of anti-aliasing or use code #2 but getting rid of the center movement?</p> <pre><code> Matrix m = new Matrix(); m.preRotate(heading, w/2, h/2); m.setTranslate(50,50); Bitmap rbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true); canvas.drawBitmap(rbmp, 50, 50, null); </code></pre> <p>UPDATE: As result of the discussion in this thread the correct version of code #2 (anti-aliasing <em>and</em> correct rotation) would look like this (offset of 50,50 omitted):</p> <pre><code> Matrix m = new Matrix(); m.setRotate(heading, w/2, h/2); Bitmap rbpm = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true); canvas.drawBitmap(rbpm, (w - rbpm.getWidth())/2, (h - rbpm.getHeight())/2, null); </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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