Jump to content

How to shrink a picture in java?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
kaila2000

kaila2000

    Newbie

  • Members
  • Pip
  • 3 posts
i've been asked to write a code to shirk a picture by 1/2 the size...here's my code:
int rlen = pixels[0].length / 2;

            int clen = pixels.length / 2;

            int[][] temp = new int[rlen][clen];

            

            for (int row = 0; row < temp.length; row++)

            {

                for (int col = 0; col < temp[0].length; col++)

                {

                    temp[row][col] = pixels[col * 2][row * 2];

                }

            }

            pixels = temp;
for some reason when i run it, it does shrink the picture but it also rotate it...can someone please help me? thx

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas

temp[row][col] = pixels[col * 2][row * 2];

You switched your rows and columns in this line. That's why it's rotating.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users