I am writing an application that draws a circle and then saves the image
as a .tif file (using JAI). I need to save the image at 600 dpi, at
least, for later printing. I can only get it to save at 72 dpi since
that is the default GraphicsConfiguration. Here is what I have tried so
far:
1) Rescale the Graphics 2d object using scale(int h, int w);
2) Rescale the Image object using getScaledInstance(int h, int w) (I
think that's right)
3) Draw 2d object 600X600 pixels and save into an image that is 100X100
pixels
4) Change rendering hints like VALUE_RENDER_QUALITY, INTERP_BICUBIC,
etc.
5) Apply AffineTransform to 2d object.
6) Try to scale using jai JAI.create("scale", pb);
All of these either reduce the quality during the scaling or crop the
image. I downloaded the Java2 source code to look at the
GraphicsConfiguration, GraphicsEnvironment, and GraphicsDevice classes
to see if there was any way I could overwrite the 72 dpi default. I am
now VERY desperate. Is there any way I can overwrite the default
GraphicsConfiguration with something like myGraphicConfig? Is there an
easier way to do this? I have posted this question at the Developer
Connection and got no response. I have also poured over the interest
lists, tutorials, tech docs, etc. and can't seem to find an answer.
Since I am not printing the .tif file immediately, I can use any of the
PrinterJob classes. Any help would be REALLY appreciated. I have now
been working on this one aspect of the program for 30 days now.
HELP!!! Here is some of my code. I can't post all of it.
public class Graph2
{
public static Frame displayFrame;
protected myCanvas displayCanvas;
protected String filename;
public static Image saveImage;
public static int Val1 = 0;
public static int Val2 = 0;
public static int highestVal = 0;
public static int TotalPay = 0;
public static int Contribution = 0;
public static int Gcounter;
public Graph2(int width, int height)
{
//System.out.println("You are in new chart");
this.filename = filename;
displayFrame = new Frame("Chart Application");
displayCanvas = new myCanvas();
setupGUI();
displayFrame.show();
displayFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
displayFrame.setVisible(false);
displayFrame.dispose();
System.exit(0);
}
});
Image blank = displayFrame.createImage(height, width);
displayCanvas.image = blank;
saveImage = displayCanvas.image;
displayFrame.pack();
}
protected void setupGUI()
{
displayFrame.setLayout(new BorderLayout());
displayFrame.add(BorderLayout.CENTER, displayCanvas);
}
public static void main(String[] args)
{
//Some jdbc stuff
//Get some numbers for drawing
String theFile =
"G:\\Projects\\myFile\\Images\\ImageInvestmt";
theFile += fileCounter;
theFile += ".tif";
Gcounter = 0;
//System.out.println("You are before new chart");
String readFile = "G:\\Projects\\GreatWest\\Images\\ImageInvestmt";
readFile += fileCounter;
readFile += ".tif";
new Graph2(600, 600);
//More jdbc stuff
try
{
RenderedOp ri = JAI.create("awtimage", saveImage);
FileOutputStream stream = new FileOutputStream(theFile);
//JAI.create("encode", ri, stream, null);
JAI.create("filestore", ri, theFile, null);
//System.out.println("You are back in main");
}
catch (Exception e)
{
System.out.println("Picture save failed: " +
e.getMessage());
}
fileCounter++;
displayFrame.dispose();
}
System.exit(0);
}
catch(SQLException ex)
{
System.out.println("The error is here: "+ex);
}
}
}
class myCanvas extends Component
{
public static Image image;
public static Graph2 chartVals;
public Object AntiAlias = RenderingHints.VALUE_ANTIALIAS_ON;
public myCanvas()
{
new myDrawer();
}
public void paint(Graphics g)
{
BufferedImage bi = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
//These values are from the database stuff
int Value1 = chartVals.Val1;
int Value2 = chartVals.Val2;
int highestVal = chartVals.highestVal;
float TP = chartVals.TotalPay;
float Cont = chartVals.Contribution;
int Percent;
Percent = (int)((Cont/TP)*100);
if (Value1 > Value2)
highestVal = Value1;
if (Value2 > Value1)
highestVal = Value2;
g = image.getGraphics();
int yCoord = 0;
Graphics2D newg = (Graphics2D) g;
//newg = bi.createGraphics();
newg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
AntiAlias);
newg.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
newg.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
newg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
newg.setColor(Color.yellow);
Ellipse2D ellipse1 = new Ellipse2D.Float(10, 20, 500, 500);
newg.draw(ellipse1);
newg.fill(ellipse1);
newg.setColor(Color.blue);
Arc2D pie1 = new Arc2D.Float(Arc2D.PIE);
pie1.setFrame(10, 20, 500, 500);
pie1.setAngleStart(0);
pie1.setAngleExtent(Percent);
//newg.scale(72.0/600, 72.0/600);
newg.draw(pie1);
newg.fill(pie1);
newg.setStroke(new BasicStroke(1.0f));
Arc2D outline2 = new Arc2D.Float(0);
outline2.setFrame(10, 20, 500, 500);
outline2.setAngleStart(0);
outline2.setAngleExtent(Value1);
newg.setColor(Color.black);
newg.draw(outline2);
newg.setStroke(new BasicStroke(1.0f));
Arc2D outline1 = new Arc2D.Float(0);
outline1.setFrame(10, 20, 500, 500);
outline1.setAngleStart(Value1);
outline1.setAngleExtent(Value2);
newg.setColor(Color.black);
newg.draw(outline1);
newg.setStroke(new BasicStroke(1.0f));
Arc2D outline3 = new Arc2D.Float(0);
outline3.setFrame(10, 20, 500, 500);
outline3.setAngleStart(Value2);
outline3.setAngleExtent(360);
newg.draw(outline3);
newg.drawImage(image, 0,0, 600, 600, this);
}
class myDrawer
{
public myCanvas canvas;
public myDrawer()
{
this.canvas = myCanvas.this;
}
}
}
I know this code will NOT compile the way it sits here, but I had to
take some code out. However, everything draws and saves fine except for
my resolution. I apologize for how messy my code is. Thanks for any
help.
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".