title: Java DirectColorModel vs. IndexColorModel when dealing with alphas
body: <p>I have a BufferedImage that I get that has an IndexColorModel.  I then wish to apply an AffineTransform with AffineTransformOP in order to create a transformed version of displayImage.</p>
  
  <p>Here's a code snippet:</p>
  
  <pre><code>int type = isRGB() ? AffineTransformOp.TYPE_BILINEAR : AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
  AffineTransformOp op = new AffineTransformOp(atx, type);
  displayImage = op.filter(displayImage, null);
  </code></pre>
  
  <p>I'm running this with many images, and from an earlier post I discovered that if I set the transform type to bilinear, then I was running out of memory because I was getting an image back with a DirectColorModel.  However, this DirectColorModel had a correct alpha channel (when I drew the image an a green background after translating it, I could see green around the whole image).  When I set the interpolation type to nearest neighbor, pixels above and to the left of the image appear black no matter what the background is.  I'm assuming this means that the alpha is not getting set.</p>
  
  <p>Can anyone tell me how to correctly set the alpha channel with an IndexColorModel, or change the AffineTransformOP parameters such that I get an IndexColorModel with the correct alpha?</p>
  
  <p>Thanks!!</p>
  
  <p>EDIT:
  Here is the desired effect, with <code>AffineTransformOp.TYPE_BINLINEAR</code>:
  <img src="https://i.imgur.com/ZOatg.jpg" alt="alt text"></p>
  
  <p>Here is the effect that I'm seeing with <code>AffineTransformOp.TYPE_NEAREST_NEIGHBOR</code>:
  <img src="https://i.imgur.com/vjA24.jpg" alt="alt text"></p>
  
  <p>The whole background is initially painted green for effect and in both cases the image is drawn at position (0, 0).</p>