File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Splitting Images into two Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Splitting Images into two" Watch "Splitting Images into two" New topic
Author

Splitting Images into two

Rodricks george
Ranch Hand

Joined: Sep 10, 2006
Posts: 97
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
Marshal

Joined: Mar 22, 2005
Posts: 42372
    
  64
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


  • Ping & DNS - my free Android networking tools app
    Rodricks george
    Ranch Hand

    Joined: Sep 10, 2006
    Posts: 97
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 42372
        
      64
    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

    Joined: Sep 10, 2006
    Posts: 97
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 42372
        
      64
    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

    Joined: Sep 10, 2006
    Posts: 97
    Yes.. Thank you sir.. I solved the problem
     
    jQuery in Action, 2nd edition
     
    subject: Splitting Images into two