Last active
December 30, 2016 21:33
-
-
Save define-private-public/d72e9f89094435d2c03a35213945b5a2 to your computer and use it in GitHub Desktop.
stb_image-Nim blog post code snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stb_image.h" | |
// Get the image data | |
int width, height, channels; | |
unsigned char *data = stbi_load("kevin_bacon.jpeg", &width, &height, &channels, STBI_default); | |
// Do what you want... | |
// Cleanup | |
stbi_image_free(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import stb_image as stbi | |
var | |
width, height, channels: int | |
data: seq[uint8] | |
data = stbi.load("kevin_bacon.png", width, height, channels, stbi.Default) | |
# No need to do any GC yourself, as Nim takes care of that for you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import stb_image as stbiw | |
# Stuff some pixels | |
var data: seq[uint8] = @[] | |
data.add(0x00) | |
data.add(0x80) | |
data.add(0xFF) | |
# save it (as monochrome) | |
stbiw.writeBMP("three.bmp", 3, 1, stbiw.Y, data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment