Skip to content

A Go package converting a monochrome 1-bit bitmap image into a set of vector paths.

License

Notifications You must be signed in to change notification settings

tunabay/go-bmppath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference MIT License

go-bmppath

Overview

Package bmppath converts a monochrome 1-bit bitmap image into a set of vector paths.

Note that this package is by no means a sophisticated tool for tracing raster images in detail. It only has the ability to create vector paths with as few paths as possible. The vector paths created keep the shape of the square pixels and look jagged.

Originally this code was written for the purpose of converting a QR Code to a print format.

Examples

source bitmap paths

Note: I draw these images manually to give an overview. Therefore, the details may be slightly different from the actual paths output by the code. It's a known mistake that multiple arrows are drawn on one path :-)

Usage

import (
	"os"

	"github.com/tunabay/go-bitarray"
	"github.com/tunabay/go-bmppath"
)

func main() {
	bmp := bitarray.NewBufferFromByteSlice([]byte{
		0b_10000001,
		0b_01000010,
		0b_00111100,
		0b_01111110,
		0b_11011011,
		0b_01111110,
		0b_00100100,
		0b_11000011,
	})

	path, err := bmppath.New(bmp, 8)
	if err != nil {
		panic(err)
	}

	_ = path.WriteSVG(os.Stdout)
}

Run in Go Playground

Documentation

License

go-bmppath is available under the MIT license. See the LICENSE file for more information.