June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -3,34 +3,29 @@ import java.awt.Graphics;
|
|||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BasicBitmapStorage
|
||||
{
|
||||
private BufferedImage image;
|
||||
public class BasicBitmapStorage {
|
||||
|
||||
public BasicBitmapStorage(final int width, final int height)
|
||||
{
|
||||
image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
|
||||
}
|
||||
private final BufferedImage image;
|
||||
|
||||
public void fill(final Color c)
|
||||
{
|
||||
Graphics g = image.getGraphics();
|
||||
g.setColor(c);
|
||||
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
}
|
||||
public BasicBitmapStorage(int width, int height) {
|
||||
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
|
||||
public void setPixel(final int x, final int y, final Color c)
|
||||
{
|
||||
image.setRGB(x, y, c.getRGB());
|
||||
}
|
||||
public void fill(Color c) {
|
||||
Graphics g = image.getGraphics();
|
||||
g.setColor(c);
|
||||
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
}
|
||||
|
||||
public Color getPixel(final int x, final int y)
|
||||
{
|
||||
return new Color(image.getRGB(x, y));
|
||||
}
|
||||
public void setPixel(int x, int y, Color c) {
|
||||
image.setRGB(x, y, c.getRGB());
|
||||
}
|
||||
|
||||
public Image getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
public Color getPixel(int x, int y) {
|
||||
return new Color(image.getRGB(x, y));
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,22 @@
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.awt.Color;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BasicBitmapStorageTest extends TestCase
|
||||
{
|
||||
public static final int WIDTH = 640, HEIGHT = 480;
|
||||
public class BasicBitmapStorageTest {
|
||||
|
||||
BasicBitmapStorage bbs = new BasicBitmapStorage(WIDTH, HEIGHT);
|
||||
@Test
|
||||
public void testHappy() {
|
||||
int width = 640;
|
||||
int height = 480;
|
||||
|
||||
public void testHappy()
|
||||
{
|
||||
bbs.fill(Color.cyan);
|
||||
bbs.setPixel(WIDTH / 2, HEIGHT / 2, Color.BLACK);
|
||||
Color c1 = bbs.getPixel(WIDTH / 2, HEIGHT / 2);
|
||||
Color c2 = bbs.getPixel(20, 20);
|
||||
assertEquals(Color.BLACK, c1);
|
||||
assertEquals(Color.CYAN, c2);
|
||||
}
|
||||
BasicBitmapStorage bbs = new BasicBitmapStorage(width, height);
|
||||
bbs.fill(Color.CYAN);
|
||||
bbs.setPixel(width / 2, height / 2, Color.BLACK);
|
||||
Color c1 = bbs.getPixel(width / 2, height / 2);
|
||||
Color c2 = bbs.getPixel(20, 20);
|
||||
|
||||
assertEquals(Color.BLACK, c1);
|
||||
assertEquals(Color.CYAN, c2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue