Skip to content

Instantly share code, notes, and snippets.

@define-private-public
Last active December 30, 2016 21:33
Show Gist options
  • Save define-private-public/d72e9f89094435d2c03a35213945b5a2 to your computer and use it in GitHub Desktop.
Save define-private-public/d72e9f89094435d2c03a35213945b5a2 to your computer and use it in GitHub Desktop.
stb_image-Nim blog post code snippets
#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);
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!
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