September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
35
Task/Bitmap/Kotlin/bitmap.kotlin
Normal file
35
Task/Bitmap/Kotlin/bitmap.kotlin
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// version 1.1.4-3
|
||||
|
||||
import java.awt.Color
|
||||
import java.awt.Graphics
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
class BasicBitmapStorage(width: Int, height: Int) {
|
||||
val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)
|
||||
|
||||
fun fill(c: Color) {
|
||||
val g = image.graphics
|
||||
g.color = c
|
||||
g.fillRect(0, 0, image.width, image.height)
|
||||
}
|
||||
|
||||
fun setPixel(x: Int, y: Int, c: Color) = image.setRGB(x, y, c.getRGB())
|
||||
|
||||
fun getPixel(x: Int, y: Int) = Color(image.getRGB(x, y))
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val width = 640
|
||||
val height = 480
|
||||
val bbs = BasicBitmapStorage(width, height)
|
||||
with (bbs) {
|
||||
fill(Color.cyan)
|
||||
setPixel(width / 2, height / 2, Color.black)
|
||||
val c1 = getPixel(width / 2, height / 2)
|
||||
val c2 = getPixel(20, 20)
|
||||
print("The color of the pixel at (${width / 2}, ${height / 2}) is ")
|
||||
println(if (c1 == Color.black) "black" else "unknown")
|
||||
print("The color of the pixel at (120, 120) is ")
|
||||
println(if (c2 == Color.cyan) "cyan" else "unknown")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue