开发者

Resizing an array

I'm supposed to resize an image given to me by half using arrays. I have no idea where to begin. I'm given a function

public static int[][] resizeImage(int[][] original, int newWd, int newHt) 

and I'm su开发者_Python百科pposed to use 2d arrays to map pixels from original to new image. Not sure if I'm giving enough info. I don't want the answer, just a hint or starting point, because I'm just not sure how to even start with this.


Ok, assuming a 100x100 image, if you had a blue pixel at [0,0] and a red pixel at [99][99], after the resizing where would you expect these pixels to be?


Draw a 4x4 grid on a piece of paper, and color each the squares with, say, one of red, green, blue, and black. Now draw an 8x8 grid, and picture how you would copy that picture from the first grid to the second. Notice what square in the original copied to what square in the target, and try to generalize that to an algorithm.

Obviously, the first grid is the original array, and the second grid is your returned array.

Did your teacher tell you how the picture should be resized? If not, you may just want to "make the pixels bigger", so each square is just copied straight to a 2x2 grid (four squares). You can get really, really fancy with your resizing algorithm (antialiasing, for instance), but I'd start simple.


This may help:
Interpolation algorithms when downscaling

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜