fix issue causing ARGB images to save weirdly with JPG and BMP (issue #415)

This commit is contained in:
benfry
2011-03-08 00:01:34 +00:00
parent 0fe67eaff9
commit cff54bee96
2 changed files with 16 additions and 53 deletions
+12 -48
View File
@@ -2768,60 +2768,24 @@ public class PImage implements PConstants, Cloneable {
*/
protected void saveImageIO(String path) throws IOException {
try {
BufferedImage bimage =
new BufferedImage(width, height, (format == ARGB) ?
BufferedImage.TYPE_INT_ARGB :
BufferedImage.TYPE_INT_RGB);
/*
Class bufferedImageClass =
Class.forName("java.awt.image.BufferedImage");
Constructor bufferedImageConstructor =
bufferedImageClass.getConstructor(new Class[] {
Integer.TYPE,
Integer.TYPE,
Integer.TYPE });
Field typeIntRgbField = bufferedImageClass.getField("TYPE_INT_RGB");
int typeIntRgb = typeIntRgbField.getInt(typeIntRgbField);
Field typeIntArgbField = bufferedImageClass.getField("TYPE_INT_ARGB");
int typeIntArgb = typeIntArgbField.getInt(typeIntArgbField);
Object bimage =
bufferedImageConstructor.newInstance(new Object[] {
new Integer(width),
new Integer(height),
new Integer((format == ARGB) ? typeIntArgb : typeIntRgb)
});
*/
int outputFormat = (format == ARGB) ?
BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
// JPEG and BMP images that have an alpha channel set get pretty unhappy.
// BMP just doesn't write, and JPEG writes it as a CMYK image.
// http://code.google.com/p/processing/issues/detail?id=415
String lower = path.toLowerCase();
if (lower.endsWith("bmp") || lower.endsWith("jpg") || lower.endsWith("jpeg")) {
outputFormat = BufferedImage.TYPE_INT_RGB;
}
BufferedImage bimage = new BufferedImage(width, height, outputFormat);
bimage.setRGB(0, 0, width, height, pixels, 0, width);
/*
Method setRgbMethod =
bufferedImageClass.getMethod("setRGB", new Class[] {
Integer.TYPE, Integer.TYPE,
Integer.TYPE, Integer.TYPE,
pixels.getClass(),
Integer.TYPE, Integer.TYPE
});
setRgbMethod.invoke(bimage, new Object[] {
new Integer(0), new Integer(0),
new Integer(width), new Integer(height),
pixels, new Integer(0), new Integer(width)
});
*/
File file = new File(path);
String extension = path.substring(path.lastIndexOf('.') + 1);
ImageIO.write(bimage, extension, file);
/*
Class renderedImageClass =
Class.forName("java.awt.image.RenderedImage");
Class ioClass = Class.forName("javax.imageio.ImageIO");
Method writeMethod =
ioClass.getMethod("write", new Class[] {
renderedImageClass, String.class, File.class
});
writeMethod.invoke(null, new Object[] { bimage, extension, file });
*/
} catch (Exception e) {
e.printStackTrace();
+4 -5
View File
@@ -11,13 +11,12 @@ X right now not in a good place--default font will be bitmapped and ugly
X http://code.google.com/p/processing/issues/detail?id=416
o need to have some kind of subsetting mode, but 'subsetting' a bad name
X changing PDF to use textMode(SHAPE) by default
_ need to update the reference for textMode(MODEL)
X saving a PGraphics as jpg using save() makes a cmyk file
X need to shut off the alpha channel when writing
X http://code.google.com/p/processing/issues/detail?id=415
_ saving a PGraphics as jpg using save() makes a cmyk file
_ need to shut off the alpha channel when writing
_ http://code.google.com/p/processing/issues/detail?id=415
_ present mode is no longer centering on macosx
_ present mode is no longer centering on osx?
_ bug: textAlign(RIGHT) is shutting off native fonts
_ makes salaryper super ugly