在Google上花了很多时间研究这个问题之后,我无法想象在C#中将Wbmp图像转换为Png格式的例子我从互联网上下载了一些Wbmp图像,我正在使用二进制编辑器查看它们.
有没有人有一个算法可以帮助我这样做或任何代码也会有所帮助.
到目前为止我知道的事情:
我完全失去了所以任何帮助将不胜感激
其他一些代码:
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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
和
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
Run Code Online (Sandbox Code Playgroud)
流程:
对Wbmp做过研究
打开X.wbmp首先检查详细信息
找出如何找到WBMP文件的宽度和高度(以便以后可以编写代码).请注意,转换长度字节集合(一旦清除MSB)的最简单方法是将实体视为base-128.
看看我更新的示例代码.
我正在尝试创建一个空的Bitmap对象,并将其宽度和高度设置为我们在(3)中得出的结果
对于每一位数据,都会尝试在创建的Bitmap对象上执行SetPixel.
当WBMP宽度不是8的倍数时填充0.
使用Save()方法保存位图.
应用程序的示例用法.假设该应用程序称为Wbmp2Png.在命令行中:
Wbmp2Png IMG_0001.wbmp IMG_0002.wbmp IMG_0003.wbmp
Run Code Online (Sandbox Code Playgroud)
该应用程序将IMG_0001.wbmp,IMG_0002.wbmp和IMG_0003.wbmp中的每一个转换为PNG文件.
这似乎完成了工作。
using System.Drawing;
using System.IO;
namespace wbmp2png
{
class Program
{
static void Main(string[] args)
{
foreach (string file in args)
{
if (!File.Exists(file))
{
continue;
}
byte[] data = File.ReadAllBytes(file);
int width = 0;
int height = 0;
int i = 2;
for (; data[i] >> 7 == 1; i++)
{
width = (width << 7) | (data[i] & 0x7F);
}
width = (width << 7) | (data[i++] & 0x7F);
for (; data[i] >> 7 == 1; i++)
{
height = (height << 7) | (data[i] & 0x7F);
}
height = (height << 7) | (data[i++] & 0x7F);
int firstPixel = i;
Bitmap png = new Bitmap(width, height);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
png.SetPixel(x, y, (((data[firstPixel + (x / 8) + (y * ((width - 1) / 8 + 1))] >> (7 - (x % 8))) & 1) == 1) ? Color.White : Color.Black);
}
}
png.Save(Path.ChangeExtension(file, "png"));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)