Draw a pixel: Difference between revisions
Content added Content deleted
(Added X86 Assembly example, showing how to do it in 32 bytes of executable code.) |
|||
Line 744: | Line 744: | ||
The color of the pixel at (100, 100) is red. |
The color of the pixel at (100, 100) is red. |
||
</pre> |
</pre> |
||
::<lang go>package main |
|||
import ( |
|||
"image" |
|||
"image/color" |
|||
"image/draw" |
|||
"image/png" |
|||
"os" |
|||
) |
|||
func main() { |
|||
// Create an 320 x 240 image |
|||
img := image.NewRGBA(image.Rect(0, 0, 320, 240)) |
|||
// fill img in white |
|||
draw.Draw(img, img.Bounds(), &image.Uniform{color.RGBA{0, 0, 0, 0}}, image.ZP, draw.Src) |
|||
// Draw a red dot at (100, 100) |
|||
img.Set(100, 100, color.RGBA{255, 0, 0, 255}) |
|||
// Save to new.png |
|||
w, _ := os.OpenFile("new.png", os.O_WRONLY|os.O_CREATE, 0600) |
|||
defer w.Close() |
|||
png.Encode(w, img) |
|||
} |
|||
</lang> |
|||
=={{header|IS-BASIC}}== |
=={{header|IS-BASIC}}== |