After spending much time researching about this on Google, I could not come across an example of converting a Wbmp image to Png format in C#
I have download some Wbmp images from the internet and I am viewing them using a Binary Editor.
Does anyone have an algorithm that will assist me in doing so or any code will also help.
Things I know so far:
- First byte is type* (0 for monochrome images)
- Second byte is called a “fixed-header” and is 0
- Third byte is the width of the image in pixels*
- Fourth byte is the height of the image in pixels*
- Data bytes arranged in rows – one bit per pixel:
Where the row length is not divisible by 8, the row is 0-padded to
the byte boundary
I am fully lost so any help will be appreciated
Some of the other code:
using System.Drawing;
using System.IO;
class GetPixel
{
public static void Main(string[] args)
{
foreach ( string s in args )
{
if (File.Exists(s))
{
var image = new Bitmap(s);
Color p = image.GetPixel(0, 0);
System.Console.WriteLine("R: {0} G: {1} B: {2}", p.R, p.G, p.B);
}
}
}
}
And
class ConfigChecker
{
public static void Main()
{
string drink = "Nothing";
try
{
System.Configuration.AppSettingsReader configurationAppSettings
= new System.Configuration.AppSettingsReader();
drink = ((string)(configurationAppSettings.GetValue("Drink", typeof(string))));
}
catch ( System.Exception )
{
}
System.Console.WriteLine("Drink: " + drink);
} // Main
} // class ConfigChecker
Process :
-
Did research on Wbmp
-
Open up X.wbmp to check details first
-
Work out how you find the width and height of the WBMP file (so that you can later write the code). Note that the simplest way to convert a collection of length bytes (once the MSB is cleared) is to treat the entity as base-128.
-
Look at sample code I updated.
-
I am trying to create an empty Bitmap object and set its width and height to what we worked out in (3)
-
For every bit of data, will try and do a SetPixel on the Bitmap object created.
-
Padded 0s when the WBMP width is not a multiple of 8.
-
Save Bitmap using the Save() method.
Example usage of the application. It is assumed that the application is called Wbmp2Png. In command line:
Wbmp2Png IMG_0001.wbmp IMG_0002.wbmp IMG_0003.wbmp
The application converts each of IMG_0001.wbmp, IMG_0002.wbmp, and IMG_0003.wbmp to PNG files.
This seems to get the job done.