0

For my project I am trying to create an ImageThumbNail class that takes whatever image and shrinking it down to exactly 50x50. I have code that only shrinks the image, but it doesn't get the pixels down to exactly 50x50.

private static int[][] thumbNailSingleChannel(int[][] pixelArray) {
 int rows = pixelArray.length/2;
 int columns = pixelArray[0].length/2;
 int[][] answer = new int[rows][columns];
 for (int r = 0; r < rows; r++) {
     for (int c = 0; c < columns; c++) {

             answer[r][c] = pixelArray[r*2][c*2];
         }
     }

 return answer;
}
V4k4
  • 33
  • 6
  • You need to change the target `rows` and `columns` to 50. You then need to calculate the scale factor (the difference between the input size and the output size) and scale the pixels accordingly – MadProgrammer Feb 14 '18 at 21:45
  • On consideration, I think there's almost certainly a better way to do this. And, [there is](https://stackoverflow.com/a/5896284/2970947). – Elliott Frisch Feb 14 '18 at 21:49
  • Are you using some GUI? Swing, JavaFx, AWT, or any other? – zlakad Feb 14 '18 at 21:49
  • @MadProgrammer may I get some further help on that, thank you! I changed the rows and columns to 50, but I don’t know how to find the scale factor and how to implement it into my code – V4k4 Feb 14 '18 at 22:00
  • @ElliottFrisch thank you! But I have to make sure that my code looks similar to this. I can utilize other classes or code that my class hasn’t learned yet, thanks again! – V4k4 Feb 14 '18 at 22:01
  • @zlakad I’m not entirely sure, but I’m using something called ImageTransformer – V4k4 Feb 14 '18 at 22:02
  • I suppose `ImageTransformer` is class in some package of 3rd party library? Please, see what did you imported (what package) to be able to use this class. – zlakad Feb 14 '18 at 22:07
  • @V4k4 `int heightScale = ((int)(50.0 / (double)pixelArray.length);`, you'll have to calculate the width scale as well... or something like it - to be honest though, Java already provides support for scaling images which is far easier then this – MadProgrammer Feb 14 '18 at 22:08

0 Answers0