GDI+ 不支持CF_DIBV5
格式但是当多个应用程序将透明图像放入它们使用的剪贴板时CF_DIBV5
(格式 17)保持 Alpha 通道的格式。
.NET Framework 无法处理CF_DIBV5
格式,以便 .NET 应用程序无法将 Alpha 图像放入剪贴板或从剪贴板检索 Alpha 图像。
有没有c#代码支持CF_DIBV5
从剪贴板到位图转换?
对不起!我正在回答我自己的问题:
[StructLayout(LayoutKind.Sequential)]
public struct BITMAPV5HEADER
{
public uint bV5Size;
public int bV5Width;
public int bV5Height;
public UInt16 bV5Planes;
public UInt16 bV5BitCount;
public uint bV5Compression;
public uint bV5SizeImage;
public int bV5XPelsPerMeter;
public int bV5YPelsPerMeter;
public UInt16 bV5ClrUsed;
public UInt16 bV5ClrImportant;
public UInt16 bV5RedMask;
public UInt16 bV5GreenMask;
public UInt16 bV5BlueMask;
public UInt16 bV5AlphaMask;
public UInt16 bV5CSType;
public IntPtr bV5Endpoints;
public UInt16 bV5GammaRed;
public UInt16 bV5GammaGreen;
public UInt16 bV5GammaBlue;
public UInt16 bV5Intent;
public UInt16 bV5ProfileData;
public UInt16 bV5ProfileSize;
public UInt16 bV5Reserved;
}
public static Bitmap CF_DIBV5ToBitmap(byte[] data)
{
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
var bmi = (BITMAPV5HEADER)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(BITMAPV5HEADER));
Bitmap bitmap = new Bitmap((int)bmi.bV5Width, (int)bmi.bV5Height, -
(int)(bmi.bV5SizeImage / bmi.bV5Height), PixelFormat.Format32bppArgb,
new IntPtr(handle.AddrOfPinnedObject().ToInt32()
+ bmi.bV5Size + (bmi.bV5Height - 1)
* (int)(bmi.bV5SizeImage / bmi.bV5Height)));
handle.Free();
return bitmap;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)