0

I found this bit of code on a similar question, but I can't figure out how to use it.

Resizing a Bitmap:

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth)
{
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

I'm also confused as to where to place this. With my initial variables? Inside the constructor, or runnable? If the bitmap I wanted to change the size of is called Background, how do I add that to this method?

Thanks in advance.

Community
  • 1
  • 1
user3720864
  • 5
  • 1
  • 6
  • don't do that, you don't need any scaled Bitmap to draw a Bitmap in different size that original one, use Canvas.drawBitmap(Bitmap, Matrix, Paint) – pskink Jul 25 '14 at 05:10
  • @pskink How would I go about setting up the matrix? I tried just adding a new Matrix called matrix, but I don't know how to actually make it do anything – user3720864 Jul 25 '14 at 05:16
  • @pskink I tried to find a way to apply this, but I'm not sure of how to do that either. I tried going off the top answer of of [this](http://stackoverflow.com/questions/6075363/android-image-view-matrix-scale-translate), but that didn't seem to work either – user3720864 Jul 25 '14 at 05:39
  • whats difficult in setRectToRect? it takes only three params, just call it, did you try it at least? – pskink Jul 25 '14 at 05:41
  • @pskink I did, and [this](http://pastebin.com/bUsxtDck) is what I came up with. The only place it didn't give me an error to put the setRectToRect was within the constructor, but I'm not sure if that is right – user3720864 Jul 25 '14 at 05:48
  • so Log.d both rects, especially viewRect – pskink Jul 25 '14 at 05:53
  • @pskink I'm not sure if I did it right, but [here's](http://pastebin.com/2dieqC6d) my logcat. On a side note, thanks for taking the time to help me. – user3720864 Jul 25 '14 at 06:05
  • comment out setRectToRect and Log.d the value of viewRect – pskink Jul 25 '14 at 06:10
  • I don't feel like I'm using the Log.d right..I'm just adding it below the line..but if that's correct then [here](http://pastebin.com/eUDsVTqT) is the new logcat – user3720864 Jul 25 '14 at 06:22
  • yes, you are using it not right, just append viewRect object to "viewRect" String – pskink Jul 25 '14 at 06:37
  • I believe I fixed [it](http://pastebin.com/sP3QEVDk) (the log, not the issue) – user3720864 Jul 25 '14 at 06:55
  • so the rect is empty, thats wrong, you need to use SurfaceHolder.Callbaxk to be notified about the real size – pskink Jul 25 '14 at 07:05
  • @pskink I can't seem to find an example of how to use that, do you happen to know of one? – user3720864 Jul 25 '14 at 07:18
  • you I know but I cannot do everything for you, just read the docs and try it yourself – pskink Jul 25 '14 at 07:22
  • @pskink Well, fair enough. Appreciate your help anyway – user3720864 Jul 25 '14 at 07:25

0 Answers0