Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Expanding an Image in Java with Pixmap  RSS feed

 
Jackson Andrew
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My goal is to expand both the height and width of an image by filling in an expanded image with a copy of the colors from the original image. Here is my code:



When I scale both the width and height by 2, I get the new Pixmap, but it doesn't expand the image. Instead it fills it in with black space.

I think there is something wrong with my inner for loops. Can someone let me know where I might be going wrong. Thanks. Any advice would be helpful.
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Easier just to use an AffineTransform, or Image#getScaledInstance()
 
Jackson Andrew
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:Easier just to use an AffineTransform, or Image#getScaledInstance()


I'm not allowed to for this assignment
 
Piet Souris
Rancher
Posts: 1980
67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Easiest is to start with outer loops that go from 0 to new width resp. new height. Then, for each value (x, y), determine the corresponding coordinates of the original image. Note that these mapped coordinates will be fractional values, say (x’ + alpha, y’ + beta).
Then determine what to do with these alpha and beta. You could discard these, use them to interpolate between surrounding pixels, et cetera.

An easier way (but probably also not allowed) is to create this new image, get its Graphics g, then simply draw the original image into it, using the appropriate draw scaling method.
(g,drawImage(oldImage, 0, 0, newWidth, newHeight, null)).
 
Campbell Ritchie
Marshal
Posts: 55720
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jackson Andrew wrote:. . . I'm not allowed to for this assignment
What sort of things do people set as assignments?

And welcome to the Ranch
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross posted to Java Forums.

See my response there for a likely reason you are not scaling the image.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!