I don't know how to scale BufferedImage, to get an image that will be available to write into file. I want to use that Scaled image to throw into canvas, because size of buffered window will change, and it depends on some parameters, but firstly i want to be able to write to file. how can i easly make it?
My code:
Paint just using some matrix to put pixels in right way (that works good, just to show how it looks like)
public Paint(Run run, boolean kConst)
{
imageCALA = new BufferedImage(run.xRange, run.yRange+areaForText, BufferedImage.TYPE_INT_ARGB);
imageStates= new BufferedImage(run.xRange, run.yRange+areaForText, BufferedImage.TYPE_INT_ARGB);
imageStrategies= new BufferedImage(run.xRange, run.yRange+areaForText, BufferedImage.TYPE_INT_ARGB);
imagekD= new BufferedImage(run.xRange, run.yRange+areaForText, BufferedImage.TYPE_INT_ARGB);
for (int i=0; i<run.xRange; i++)
for ( int j=0 ; j<run.yRange+areaForText; j++)
{
if (run.temporary[i][j].cellEmpty)
{
imageCALA.setRGB(i, j, Color.WHITE.getRGB());
imageStates.setRGB(i, j, Color.WHITE.getRGB());
imageStrategies.setRGB(i, j, Color.WHITE.getRGB());
imagekD.setRGB(i, j, Color.WHITE.getRGB());
}
else {
if ( run.temporary[i][j].learningAutomata)
imageStrategies.setRGB(i, j, Color.MAGENTA.getRGB());
if ( run.temporary[i][j].learningAutomata && run.temporary[i][j].sharingPayout)
imageCALA.setRGB(i, j, Color.RED.getRGB());
if ( run.temporary[i][j].state=='C')
imageStates.setRGB(i, j, Color.RED.getRGB());
if ( run.temporary[i][j].strategy.buffor=='C')
imageStrategies.setRGB(i, j, Color.RED.getRGB());
if (run.temporary[i][j].learningAutomata && !run.temporary[i][j].sharingPayout)
imageCALA.setRGB(i, j, Color.ORANGE.getRGB());
if (run.temporary[i][j].strategy.buffor=='P')
imageStrategies.setRGB(i, j, Color.ORANGE.getRGB());
if (!kConst)
for (int c=0; c<8; c++)
{
if (run.temporary[i][j].strategy.kMax==c)
{
int g = 100;
int b = 0;
int con =40;
int p = (Color.ORANGE.getAlpha()<<24) | (Color.ORANGE.getRed()<<16)
| (g+(con*c)<<8) | b+(con*b);
imagekD.setRGB(i, j, p);
}
}
else if (kConst)
imagekD.setRGB(i, j, Color.ORANGE.getRGB());
else
imagekD.setRGB(i, j, Color.WHITE.getRGB());
if (!run.temporary[i][j].learningAutomata && run.temporary[i][j].sharingPayout)
imageCALA.setRGB(i, j, Color.BLUE.getRGB());
if (run.temporary[i][j].state=='D')
imageStates.setRGB(i, j, Color.BLUE.getRGB());
if (run.temporary[i][j].strategy.buffor=='D')
{
imageStrategies.setRGB(i, j, Color.BLUE.getRGB());
}
if (!run.temporary[i][j].learningAutomata && !run.temporary[i][j].sharingPayout)
imageCALA.setRGB(i, j, Color.GREEN.getRGB());
if (run.temporary[i][j].strategy.buffor=='K')
imageStrategies.setRGB(i, j, Color.GREEN.getRGB());
}
}
}
public void PrintToFile(File fCALA, File fStates, File fStrategies,File fkD) throws IOException
{
ImageIO.write(imageCALA, "png", fCALA);
ImageIO.write(imageStates, "png", fStates);
ImageIO.write(imageStrategies, "png", fStrategies);
ImageIO.write(imagekD, "png", fkD);
}
and some try section in my main class
try
{
paint.PrintToFile(new File("Image\\outputCALA.png"), new File("Image\\outputStates.png")
, new File("Image\\outputStrategies.png"), new File("Image\\outputkD.png"));
}
catch (IOException e)
{
System.out.println("error"+e);
}