• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Splitting Images into two

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

I want to split a png file into two parts using co ordinates, how can i achieve this. please through some light on the same.

-Thanks with regards,

Rodricks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The rough outline would be
  • load the image using javax.imageio.ImageIO.read, which will give you a BufferedImage
  • create sub-images using the BufferedImage.getSubimage method
  • save those using javax.imageio.ImageIO.write

  •  
    Rodricks george
    Ranch Hand
    Posts: 97
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Dear Sir,

    Thanks for the reply. I want to split up images horizontally in to two pieces. How can i set the co ordinates.

    -Thanks with regards,

    Rodricks
     
    Ulf Dittmer
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you have an image with the corners (0,0), (w,0), (w,h) and (0,h), what would be the coordinates for the two subimages?

    I'll give a clue:

    1st image: (0,0), (xxx,0), (xxx,h) and (0,h)

    2nd image: (xxx+1,0), (w,0), (w,h) and (xxx+1,h)

    What value would "xxx" have? You need to consider two cases: "w" is even, and "w" is odd.
     
    Rodricks george
    Ranch Hand
    Posts: 97
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Dear Sir,

    Here the code i implemented for splitting images into two horizontally





    If i want to split horizontally and vertically by passing the co ordinates at any position, how can i achieve this.

    getSubimage(x,y,w,h)

    thanks with regards,
    Rodricks.
     
    Ulf Dittmer
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The code you posted has a bug. Compare the height of the two images with the heigth of the original one. Then have a look at the pseudo-code I posted before.

    If i want to split horizontally and vertically by passing the co ordinates at any position, how can i achieve this.


    Not sure I understand what you're asking. If you know at which position you want to split the image, you can use appropriate parameters in the call to getSubimage.
     
    Rodricks george
    Ranch Hand
    Posts: 97
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes.. Thank you sir.. I solved the problem
     
    These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic