B
This commit is contained in:
parent
e5e8880e41
commit
518da4a923
1019 changed files with 15877 additions and 0 deletions
36
Task/Bitmap/Java/bitmap-1.java
Normal file
36
Task/Bitmap/Java/bitmap-1.java
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BasicBitmapStorage
|
||||
{
|
||||
private BufferedImage image;
|
||||
|
||||
public BasicBitmapStorage(final int width, final int height)
|
||||
{
|
||||
image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
|
||||
}
|
||||
|
||||
public void fill(final Color c)
|
||||
{
|
||||
Graphics g = image.getGraphics();
|
||||
g.setColor(c);
|
||||
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
}
|
||||
|
||||
public void setPixel(final int x, final int y, final Color c)
|
||||
{
|
||||
image.setRGB(x, y, c.getRGB());
|
||||
}
|
||||
|
||||
public Color getPixel(final int x, final int y)
|
||||
{
|
||||
return new Color(image.getRGB(x, y));
|
||||
}
|
||||
|
||||
public Image getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
}
|
||||
19
Task/Bitmap/Java/bitmap-2.java
Normal file
19
Task/Bitmap/Java/bitmap-2.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import java.awt.Color;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BasicBitmapStorageTest extends TestCase
|
||||
{
|
||||
public static final int WIDTH = 640, HEIGHT = 480;
|
||||
|
||||
BasicBitmapStorage bbs = new BasicBitmapStorage(WIDTH, HEIGHT);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue