Skip to content
Snippets Groups Projects
Commit ca1b6c27 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

code for generating scale image

parent 1a31b6c4
No related branches found
No related tags found
1 merge request!110uploading of big data overlay gives proper error message
package lcsb.mapviewer.converter.graphics; package lcsb.mapviewer.converter.graphics;
import java.awt.Color; import java.awt.Color;
import java.awt.Desktop;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.commands.ColorExtractor;
...@@ -37,4 +45,42 @@ public class ConverterTest { ...@@ -37,4 +45,42 @@ public class ConverterTest {
} }
} }
@Test
@Ignore("it's just code for generating scale")
public void testX() throws IOException {
BufferedImage tmpBI = new BufferedImage(900, 100, BufferedImage.TYPE_INT_ARGB);
Graphics2D tmpGraphics = tmpBI.createGraphics();
int startX = 10;
int startY = 15;
int stepSize = 40;
int height = 25;
tmpGraphics.setColor(Color.BLACK);
for (int i = 0; i < 21; i++) {
tmpGraphics.drawLine(startX + i * stepSize, height+startY, startX + i * stepSize, height*2);
String str = ""+((double)(i-10))/((double)(10));
tmpGraphics.drawString(str, startX + i * stepSize, height*2+startY);
}
for (int i = 0; i < 10 * stepSize; i++) {
double ratio = ((double) i) / ((double) (10 * stepSize));
tmpGraphics.setBackground(getColor(ratio, Color.BLUE, Color.WHITE));
tmpGraphics.setColor(getColor(ratio, Color.BLUE, Color.WHITE));
tmpGraphics.drawRect(startX + i, startY , 1, height);
}
for (int i = 0; i < 10 * stepSize; i++) {
double ratio = ((double) i) / ((double) (10 * stepSize));
tmpGraphics.setBackground(getColor(ratio, Color.WHITE, Color.RED));
tmpGraphics.setColor(getColor(ratio, Color.WHITE, Color.RED));
tmpGraphics.drawRect(10 * stepSize + startX + i, startY , 1, height);
}
ImageIO.write(tmpBI, "PNG", new File("tmp.png"));
Desktop.getDesktop().open(new File("tmp.png"));
}
private Color getColor(double d, Color startColor, Color endColor) {
return new Color((int) (startColor.getRed() + d * (endColor.getRed() - startColor.getRed())), //
(int) (startColor.getGreen() + d * (endColor.getGreen() - startColor.getGreen())), //
(int) (startColor.getBlue() + d * (endColor.getBlue() - startColor.getBlue())));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment