title: How do you generate an image of a specific size in Java?
body: <p>I need to generate images (the format of images does not matter) of a given size (For example, <code>10KB</code>, <code>100KB</code>, <code>1MB</code>, <code>10MB</code>, etc), using <strong>Java</strong>. The image can be any shape which is filled a background color, no restrictions for the content of images.</p>
  
  <p><strong>Edit #1:</strong> The sizes of the images which are going to be created are changeable, so I am looking for <strong>an efficient way</strong> in terms of <strong>memory usage</strong> in order to be safe from the <strong>Java</strong> <code>heap space</code> exception while creating images.</p>
  
  <p><strong>Edit #2:</strong> I am getting the <code>java.lang.IllegalArgumentException: Dimensions (width=48000 height=48000) are too large</code> exception when I try to generate an image with the dimensions <code>48000x48000</code> using the Graphics2D library, which is necessary in order to generate images with large file sizes.</p>
  
  <p><strong>Edit #3:</strong> When the dimensions get bigger, I experience the <code>java.lang.OutOfMemoryError: Java heap space</code> exception even though I have manually configured the <code>-Xmx</code> parameter of the Java program that does this.</p>