• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Splitting Images into two

 
Rodricks george
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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
    • 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: 42968
    73
    • Mark post as helpful
    • send pies
    • 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
    • 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: 42968
    73
    • Mark post as helpful
    • send pies
    • 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
    • Quote
    • Report post to moderator
    Yes.. Thank you sir.. I solved the problem
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic