• 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

Cut the image Horizontally or Vertically via java

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have scanned booked images...I want to cut vertically many times...
Sometimes i want to cut it horizontally.

I'm looking for a standalone java  jar to do this

Can someonehelp help me with a program?

Thanks
 
Saloon Keeper
Posts: 10743
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not too difficult to do with a BufferedImage. A BufferedImage is essentially a 2D array of pixels and you'd need one for your original image and one for each of your slices. Then create loops to copy a region of pixels from one to the other.
 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any reference or example would be helpful?
 
Bartender
Posts: 5466
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the API of the BufferedImage class. There is a method that does exactly what you want.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is a one time activity, this can be also done in image editors like photoshop. One can design action scripts and run it on all of them at one go.
 
Bartender
Posts: 208
14
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joseph Michael wrote:Any reference or example would be helpful?



This will cut the image in half:

[Code removed because it is a complete solution and the OP has not responded with their own code first]
 
Bartender
Posts: 242
27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An image is essentially a grid of pixels. A pixel is a singular point of color, with a red/green/blue component. However this detail doesn't matter for the logic of cutting an image in half.
Imagine, for simplicity's sake, that we have the following grid of integers:

[1, 2, 3, 4
4, 5, 6, 7
7, 8, 9, 9,
3, 4, 5, 6]

Which forms a 4 x 4 image.

What pixels would you need to keep in order to cut the grid horizontally? Well you'd need to keep either the top half or the bottom half:

[1, 2, 3, 4
4, 5, 6, 7]

or:

[7, 8, 9, 9,
3, 4, 5, 6]

What pixels would you need to do vertically? The first or second half, going from right to left.

[1, 2
4, 5
7, 8
3, 4]

or:

[3, 4
6, 7
9, 9,
5, 6]

Can you write a loop that would do this for a 2D Array of integers?
(hint: it's going to be a nested loop with one of your indices being x, and the other being y.)
If you can do that, then you're 90% of the way there to doing it with an Image.
 
Carey Brown
Saloon Keeper
Posts: 10743
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic