• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Expanding an Image in Java with Pixmap

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)).
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cross posted to Java Forums.

See my response there for a likely reason you are not scaling the image.
reply
    Bookmark Topic Watch Topic
  • New Topic