如何在.Net中使用32位alpha混合BMP

时间:2021-12-02 07:10:34

Is there any way to use this kind of format in .Net (C#)? I want to use the same skin format that uTorrent uses in my app, but i can't get the transparent background. Any ideas? Thanks for your time.

有没有办法在.Net(C#)中使用这种格式?我想使用uTorrent在我的应用程序中使用的相同皮肤格式,但我无法获得透明背景。有任何想法吗?谢谢你的时间。

3 个解决方案

#1


3  

You need to do two things:

你需要做两件事:

  • Copy your bitmap onto the form as background.
  • 将您的位图复制到窗体上作为背景。

  • Call the UpdateLayeredWindow (user32.dll) to enable per-pixel alpha transparency.
  • 调用UpdateLayeredWindow(user32.dll)以启用每像素Alpha透明度。

The code is a liitle bit bulky, but here is a very nice sample application with source code: Per Pixel Alpha Blend in C#

代码有点笨拙,但这是一个非常好的示例应用程序,包含源代码:C#中的Per Pixel Alpha Blend

#2


2  

The PixelFormat enumeration lists the formats of 'bitmaps' you can create in .Net, so you'd want PixelFormat.Format32bppArgb:

PixelFormat枚举列出了您可以在.Net中创建的“位图”格式,因此您需要PixelFormat.Format32bppArgb:

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx

http://msdn.microsoft.com/en-us/library/3z132tat.aspx

However I'm not entirely sure that the BMP file format supports transparency - so you would have to save the file as perhaps a PNG file instead.

但是我不完全确定BMP文件格式支持透明度 - 所以你必须将文件保存为PNG文件。

#3


2  

While the BMP format does support an alpha channel, Windows ignores it. Luckily, the format is rather simple and you can read it using System.IO.BinaryReader then create a Drawing.Bitmap using the LockBits and UnlockBits methods to write the data to it.

虽然BMP格式确实支持alpha通道,但Windows忽略它。幸运的是,格式非常简单,您可以使用System.IO.BinaryReader读取它,然后使用LockBits和UnlockBits方法创建Drawing.Bitmap以将数据写入其中。

#1


3  

You need to do two things:

你需要做两件事:

  • Copy your bitmap onto the form as background.
  • 将您的位图复制到窗体上作为背景。

  • Call the UpdateLayeredWindow (user32.dll) to enable per-pixel alpha transparency.
  • 调用UpdateLayeredWindow(user32.dll)以启用每像素Alpha透明度。

The code is a liitle bit bulky, but here is a very nice sample application with source code: Per Pixel Alpha Blend in C#

代码有点笨拙,但这是一个非常好的示例应用程序,包含源代码:C#中的Per Pixel Alpha Blend

#2


2  

The PixelFormat enumeration lists the formats of 'bitmaps' you can create in .Net, so you'd want PixelFormat.Format32bppArgb:

PixelFormat枚举列出了您可以在.Net中创建的“位图”格式,因此您需要PixelFormat.Format32bppArgb:

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx

http://msdn.microsoft.com/en-us/library/3z132tat.aspx

However I'm not entirely sure that the BMP file format supports transparency - so you would have to save the file as perhaps a PNG file instead.

但是我不完全确定BMP文件格式支持透明度 - 所以你必须将文件保存为PNG文件。

#3


2  

While the BMP format does support an alpha channel, Windows ignores it. Luckily, the format is rather simple and you can read it using System.IO.BinaryReader then create a Drawing.Bitmap using the LockBits and UnlockBits methods to write the data to it.

虽然BMP格式确实支持alpha通道,但Windows忽略它。幸运的是,格式非常简单,您可以使用System.IO.BinaryReader读取它,然后使用LockBits和UnlockBits方法创建Drawing.Bitmap以将数据写入其中。