title: Resizing and rotating an image in Android
body: <p>I'm trying to rotate and resize an image in Android.  The code I have is as follows, (taken from <a href="http://www.anddev.org/resize_and_rotate_image_-_example-t621.html" rel="nofollow noreferrer">this</a> tutorial):</p>
  
  <p>UPDATE: More code added below for more constructive feedback</p>
  
  <pre><code>     public class AnimatedSprite {
          private Bitmap bitmap;
          private double posX, posY;
          private double velocityX, velocityY;
          private int width, height;
          private int numFrames, frameRate, curFrame;
          private int startFrame, endFrame;
          private Rect dstRect, srcRect;
          private long lastTime, lastFrameTime;
          private boolean looping;
          private enum SpaceshipState {ALIVE, EXPLODE, DEAD};
          public SpaceshipState curState;
          private int respawnTime;
  
  
          public AnimatedSprite(Context context, int id, int frames, int fps) {
              this.bitmap = BitmapFactory.decodeResource(context.getResources(),id);
              this.posX = 0;
              this.posY = 0;
              this.velocityX = 0;
              this.velocityY = 0;
              this.numFrames = frames;
              this.frameRate = fps;
              this.width = this.bitmap.getWidth() / frames;
              this.height = this.bitmap.getHeight();
              this.dstRect = new Rect((int)this.posX,(int)this.posY,(int)this.posX+this.width,(int)this.posY+this.height);
              this.startFrame = 0;
              this.endFrame = frames-1;
              this.looping = true;
              this.lastFrameTime = 0;
              this.respawnTime = 0;
              this.setFrameRect(this.startFrame);
          }
              .
              .
              //Other methods
              .
              .
  
           //Returns a rotated copy of the AnimatedSprite a
      public AnimatedSprite rotateSprite(AnimatedSprite originalSprite, float angle)
      {
                AnimatedSprite rotatedSprite = originalSprite;
  
              int orgHeight = originalSprite.bitmap.getHeight();
              int orgWidth = originalSprite.bitmap.getWidth();
  
              //Create manipulation matrix
              Matrix m = new Matrix();
              // resize the bit map
              m.postScale(.25f, .25f);
              // rotate the Bitmap by the given angle
                      //Static angle for testing
              m.postRotate(180);
              //Rotated bitmap
              Bitmap rotatedBitmap = Bitmap.createBitmap(originalSprite.bitmap, 0, 0,
                      orgWidth, orgHeight, m, true); 
              //Set the new sprite bitmap to the rotated bitmap and return
              rotatedSprite.bitmap = rotatedBitmap; 
  
              return rotatedBitmap;
         }
  
  }
  </code></pre>
  
  <p>The image seems to rotate just fine, but it doesn't scale like I expect it to.  I've tried different values between 0 and .99, but the image only gets more pixelized as I reduce the scale values, but it remains that same size visually; whereas the goal I'm trying to achieve is to actually shrink it visually.  I'm not sure what to do at this point, any help is appreciated.</p>