0
因此,当我从DLL中提取图像并将其放入图像控件后,它是一个BitmapImage。要将它打包回dll,必须将其转换回图像。我怎样才能将它转换回图像,我怎样才能将它重新打包回dll?这全是用c#写的wpf。将位图转换为图像
private void compileDLL_Click(object sender, RoutedEventArgs e)
{
string sourcePath = Directory.GetCurrentDirectory() + "\\PCAngelResources.dll";
//destination path
string dllname = textBox1.Text + "_PCAngelResources.dll";
string targetPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string destFile = System.IO.Path.Combine(targetPath, dllname);
System.IO.File.Copy(sourcePath, destFile, true);
//lstImages = new Dictionary<string, Bitmap>();
//string filename = "PCAngelResources.dll";
Assembly pcangdll = Assembly.LoadFile(sourcePath);
System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture;
ResourceManager rm = new ResourceManager("PCAngelResources.DynResources", pcangdll);
rs = rm.GetResourceSet(culture, true, true);
ResourceWriter writer = new ResourceWriter(destFile);
foreach (DictionaryEntry resource in rs)
{
resources.Add((string)resource.Key);
if (resource.Key.Equals("Branding") || resource.Key.Equals("Advertising"))
{
if (resource.Key.Equals("Branding"))
{
writer.AddResource("Branding", image5.Source);
//System.Object obj = rm.GetObject((string)resource.Key);
//lstImages.Add((string)resource.Key, (Bitmap)obj);
}
else
if (resource.Key.Equals("Advertising"))
{
writer.AddResource("Advertising", image6.Source);
}
}
}
writer.Generate();
System.Windows.MessageBox.Show("Done", "Process Finished", MessageBoxButton.OK, MessageBoxImage.Asterisk, MessageBoxResult.OK);
}
当我做writer.Generate(),以使新的dll我得到以下错误: 型“System.Runtime.Serialization.SerializationException”未处理的异常出现在mscorlib.dll
其他信息:类型'System.Windows.Media.Imaging.BitmapFrameDecode'in Assembly'PresentationCore,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'未标记为可序列化。
一些示例代码? – 2009-07-28 19:37:32