• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Crop an image in Java

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I crop a JPEG image in JAVA maintaining the aspect ratio of the image. Help will be appreciated.
Thanks,
Amit.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I think maybe you might be using the wrong word. When you crop an image, typically, you are cropping to a specific bound region. Therefor, keeping the aspect ratio is nonrelivent.
However, if you are speaking of simply resizing the image, then keeping the aspect ratio is relivent.
Let's clear this up first, then we can get to the nitty gritty.
 
Amit Shanker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gregg,
You are right. I have not worded my question correctly. Actually, I want to crop an image to get the aspect ratio I want.
If the original aspect ratio of image is 2 ( 200 x 100 pixels image size), I may want to crop the image to get the aspect ratio of 1 (100 x 100 pixels image size) reducing 50 pixels on either sides.
Hope I'm clear this time.
Thanks,
Amit.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amit Shanker:
Hi Gregg,
You are right. I have not worded my question correctly. Actually, I want to crop an image to get the aspect ratio I want.
If the original aspect ratio of image is 2 ( 200 x 100 pixels image size), I may want to crop the image to get the aspect ratio of 1 (100 x 100 pixels image size) reducing 50 pixels on either sides.
Hope I'm clear this time.
Thanks,
Amit.


Interesting, because going from a 200px x 100px to a 100px x 100px is not keeping the aspect ratio. You are turning a rectangle into a square. If your image has a larger width than height, then resizing the image and keeping the aspect ratio will always leave a width greater than the height.
On the other hand, if you want to completely chop off 100px off the width (this would be cropping) but the image is not really being resized, then that would be different. In this case, ratio does not come into play at all.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic