resourcelib
resourcelib copied to clipboard
[HowTo] DIB to DDB, how to use RT_BITMAP when you retrieve them from a resource file
When retrieving a DeviceIndependantBitmap from a ResourceFile (exe, dll, ...) you might be stuck with a funky BMP file upside down with wrong colors, especially if it was an indexed one.
I'm sharing with you my work after headbanging my head on the walls for a few months: https://github.com/MetasharpNet/StarWarsRebellionEditor.NET/blob/master/SwRebellionEditor/ResourceHelpers/DIB.cs
With that, most of you will be able to use your bitmap resources properly and display them in a picture box, or save them to your harddrive.
Usage is simple : var ddbBitmap = DIB.ToDDB(myBitmapResource.Bitmap); // to get a ddb bitmap you can display in your app or DIB.ToDDB(myBitmapResource.Bitmap, "myfilepath.bmp"); // to write to disk a ddb bitmap 100% identical to resource helper output
I have just done the work for DIB bitmaps in 8 bits indexed colors but the code should be pretty easy to understand to extend it.
to me the lib just felt bugged/missing features in quite many cases.
Please feel free to contribute improvements with tests so that others can benefit!
I don't understand the way this lib is architectured.
What's your question?
The library evolved from some copy-pasted code written by someone else in 2006, it has been a while.
https://www.codeproject.com/Articles/13355/Modification-of-Version-Information-Resources-in-C https://www.codeproject.com/Articles/27373/File-Resource-Management-Library-NET https://code.dblock.org/2008/08/10/file-resource-management-library-net.html
You should rewrite it if you feel you can do better, or improve it.
I have better things to do now that I'm done. I shared my working code for all the specific cases I had to help you all. I hope someone owning the lib will do the update for others. But regarding myself, I don't have that time. Sorry, I'm doing dev for fun nowadays, it's no longer my job and I don't want to spend time on getting familiar with the Pull Request stuff.
thank you for your help
I heavily updated my code to manage the addition of new entries and some other resource types such as a customly named folder "303" for my needs.
I heavily updated my function that had in fact some bugs. Now I directly build myself a byte[] that I turn into an in memory ddb bitmap or into a ddb file depending on arguments. Check the source code. I'm so relieved to have it finally working at 100%.
https://github.com/MetasharpNet/StarWarsRebellionEditor.NET/blob/master/SwRebellionEditor/ResourceHelpers/DIB.cs