Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    /*
     Edited Answer to this question: 
     http://stackoverflow.com/questions/12458907/how-can-i-crop-an-image-with-negative-crop-boundaries-in-java

              (1) 
          +---------------------------+
 (2)      |                           |
  +-----------------------------+     |
  |       |                     |     |
  |       |                     |     |
  |       |                     |     |
  |       |                     |     |
  +-----------------------------+     |
          |                           |
          +---------------------------+

     How it's done:
     - Crop the intersection of sourceImage (1) and destImage (2) into tempImage
     - Create destImage with (complete) size of (2)
     - Place tempImage into destImage with the correct border on the left (that is (2)-(1))
     
     
     */


// sourceimage is 952x420
File sourceFile = new File("/some/file");

// destimage should be cropped to 632x294 by 64, -19 boundaries
File destFile = new File("/some/other/file");

BufferedImage sourceImage = ImageIO.read(sourceFile);

// Crop the piece you need from the source image this way:
// where 613 == 632-19
BufferedImage tempImage = sourceImage.getSubimage(64, 0, 613, 294);

// Create the new image that is the size of the resulting image
BufferedImage destImage = new BufferedImage(632, 294, sourceImage.getType());

// Then, you place the tempImage in the destImage:
Graphics2D g2 = destImage.createGraphics();
g2.drawImage(tempImage, 19, 0, 632, 294, null);
g2.dispose();

ImageIO.write(destImage, sourceImage.getType(), destFile);