resourcelib icon indicating copy to clipboard operation
resourcelib copied to clipboard

[HowTo] DIB to DDB, how to use RT_BITMAP when you retrieve them from a resource file

Open MetasharpDev opened this issue 2 years ago • 7 comments

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.

MetasharpDev avatar Jan 24 '23 00:01 MetasharpDev

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!

dblock avatar Jan 24 '23 19:01 dblock

I don't understand the way this lib is architectured.

MetasharpDev avatar Jan 24 '23 20:01 MetasharpDev

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.

dblock avatar Jan 26 '23 19:01 dblock

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.

MetasharpDev avatar Jan 26 '23 20:01 MetasharpDev

thank you for your help

dblock avatar Jan 26 '23 23:01 dblock

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.

MetasharpDev avatar Feb 02 '23 09:02 MetasharpDev

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

MetasharpDev avatar Aug 16 '23 06:08 MetasharpDev