-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.2
-
x86
-
windows_nt
Name: skT45625 Date: 06/06/2000
java version "1.2.2"
Classic VM (build JDK 1.2.2-001 native threads, symcjit)
/*
*
* File: jpg.java
*
* Brief Overview:
*
* Demonstrates bug when encoding an INDEXED .jpg with ANTIALIASING
*
* .jpg files created from an INDEXED BufferedImage will be missing graphics
* drawn when anti aliasing is enabled.
*
* Author: Lory Molesky (###@###.###)
*
*
*
* compile with
*
* javac jpg.java
*
* execute with
*
* java jpg
*
* examine resulting .jpg files
*
* indexed.jpg, rgb.jpg
*
* indexed.jpg has missing graphics.
*
*/
import java.awt.*;
import java.awt.image.*;
import java.awt.image.BufferedImage;
import java.io.*;
import com.sun.image.codec.jpeg.*;
public class jpg {
static int Display_height;
static int Display_width;
public static void drawBuffer(Graphics2D g2)
{
RenderingHints RHAnti = new
RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
//
// Frame the background.
//
g2.setColor(Color.black);
g2.fillRect(0,0,Display_width,Display_height);
int offset = 10;
int offset2 = offset * 2;
g2.setColor(Color.white);
g2.fillRect(offset,offset,Display_width - offset2,Display_height -
offset2);
//
// Enable antialiasing.
//
g2.setRenderingHints(RHAnti);
//
// Draw a horizontal bar half way down.
//
g2.setColor(Color.gray);
g2.fillRect(0,Display_height/2 - offset/2,Display_width, offset);
//
// A line across one diaganal
//
g2.setColor(Color.black);
g2.drawLine(0,0,Display_width,Display_height);
//
// A line across another diaganal
//
g2.setColor(Color.green);
g2.drawLine(0,Display_height,Display_width,0);
}
public static void main(String[] argv)
{
//
// Width, height of the image.
//
Display_height = 200;
Display_width = 300;
//
// Create two buffered images, one with imageType INT_RGB, the other
BYTE_INDEXED
//
BufferedImage biRgb = new BufferedImage(Display_width, Display_height,
BufferedImage.TYPE_INT_RGB);
BufferedImage biIndexed = new BufferedImage(Display_width,
Display_height, BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D g2 = null;
Graphics2D g2b = null;
g2 = biRgb.createGraphics();
g2b = biIndexed.createGraphics();
//
// draw the graphics into both buffered images.
//
drawBuffer(g2);
drawBuffer(g2b);
//
// Write the buffered images to two files.
// The resulting INDEXED .jpg will be missing all graphic operations
// written in the context of anti aliasing.
//
EncodeFile(biRgb, "rgb.jpg");
EncodeFile(biIndexed, "indexed.jpg");
}
//
// Convert a BufferedImage to a .jpg
//
public static void EncodeFile(BufferedImage bi, String filename)
{
FileOutputStream out = null;
try {
File file = new File(".", filename);
out = new FileOutputStream(file);
} catch (java.io.IOException e) {
System.err.println("Cannot create ./" + filename);
System.exit(1);
}
try {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(bi);
} catch (java.io.IOException e) {
System.err.println("I/O exception");
System.exit(1);
}
}
}
(Review ID: 105803)
======================================================================
- duplicates
-
JDK-4214249 drawImage() doesn't draw byte indexed images into each other on win32.
-
- Resolved
-