Bitmap Drawing API for Textures

I’ve just finished and uploaded my project to GitHub:
__https://github.com/ProtoTurtle/UnityBitmapDrawing__

Example project here:
__https://github.com/ProtoTurtle/BitmapDrawingExampleProject__

This uses a MIT license so you can do pretty much anything with it as long as you keep the license intact. Commercial projects, further open source, etc. are all fine.

Bitmap Drawing API
At it’s core this library provides and easy way to manipulate your textures as bitmaps. I find it very useful for visual debugging, creating procedural art or creating tools. You only need one file!

You have an existing texture or you create an empty texture and you can draw lines, circles and rectangles on it (filled with color or just the outline).

Features

    • DrawPixel(position, color) - Draws a pixel but with the top left corner being position (x = 0, y = 0)
  • DrawLine(start, end, color) - Draws a line between two points

  • DrawCircle(position, radius, color) - Draws a circle

  • DrawFilledCircle(position, radius, color) - Draws a circle filled with a color

  • DrawRectangle(rectangle, color) - Draws a rectangle or a square

  • DrawFilledRectangle(rectangle, color) - Draws a rectangle or a square filled with a color

  • FloodFill(position, color) - Starts a flood fill of a certaing at the point

Uses Extension Methods so it’s super simple to start using, you only type

using ProtoTurtle.BitmapDrawing;

And all the bitmap drawing methods are available to your Texture2D instances.

I’m looking for feedback on this and I’m taking feature requests. I just wanted to get this first version out and see if there’s any interest in this tool.

Coming up next:

  • Faster flood fill (the bottleneck is mostly comparing Unity’s Color structs) - if anyone has a good idea about this, please let me know! Running the flood fill with ints instead of Colors makes it a ton faster but then the problem is converting the Colors to ints and then back to Colors for SetPixels.
  • A buffer of the bitmap that get’s uploaded on Apply() but doesn’t do any SetPixel() calls before that.

There’s still a lot of work left but hopefully this is useful to some developers already. I’ve submitted the first version to Asset Store and it’s still pending but you can get it off GitHub already and give it a try.

1 Like

Wouldn’t using Color32 byte[4] be just as good? They are interchangeable.

I tried a few different things, Color32 (byte[4]), and a single uint for each color based on the Color32 bytes but I couldn’t make it faster. I’m going to update it soon with a flood fill that does much less comparisons of already visited nodes so that boosted the performance quite a bit.