我有一个图像(PNG文件)具有设置为50%不透明的alpha通道。当我尝试在TransparencyKey设置为白色并且背景颜色设置为白色的表单上绘制图像时,我希望图像被绘制为50%透视。但是,它首先与背景颜色混合,因此它完全不透明。有没有办法解决?我不想设置窗体的不透明属性,因为窗体上的某些图像需要半透明,有些图像需要不透明。透明Winform与图像
1
A
回答
1
我结束了使用分层的窗口,使用WS_EX_LAYERED扩展窗口样式。
0
我不认为你可以。我们有一个启动画面,我们做了这样的事情,但我们最终捕获了屏幕并将其设置为表单的背景图像。显然,这似乎只有工作,如果屏幕更改,表单的背景不会,而且事情看起来很奇怪。如果你找到了更好的方法,我很想知道它。
这里是捕捉屏幕的代码,只需设置ScreenRect的形式屏幕坐标和呼叫处理():
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace TourFactory.Core.Drawing
{
public class CaptureScreenCommand
{
#region Initialization and Destruction
public CaptureScreenCommand()
{
}
#endregion
#region Fields and Properties
// BitBlt is a multipurpose function that takes a ROP (Raster OPeration) code
// that controls exactly what it does. 0xCC0020 is the ROP code SRCCOPY, i.e.
// do a simple copy from the source to the destination.
private const int cRasterOp_SrcCopy = 0xCC0020; // 13369376;
private Rectangle mScreenRect;
/// <summary>
/// Gets or sets the screen coordinates to capture.
/// </summary>
public Rectangle ScreenRect
{
get { return mScreenRect; }
set { mScreenRect = value; }
}
#endregion
#region Methods
public Image Process()
{
// use the GDI call and create a DC to the whole display
var dc1 = CreateDC("DISPLAY", null, 0, 0);
var g1 = Graphics.FromHdc(dc1);
// create a compatible bitmap the size of the form
var bmp = new Bitmap(mScreenRect.Width, mScreenRect.Height, g1);
var g2 = Graphics.FromImage(bmp);
// Now go retrace our steps and get the device contexts for both the bitmap and the screen
// Note: Apparently you have to do this, and can't go directly from the aquired dc or exceptions are thrown
// when you try to release the dcs
dc1 = g1.GetHdc();
var dc2 = g2.GetHdc();
// Bit Blast the screen into the Bitmap
BitBlt(dc2, 0, 0, mScreenRect.Width, mScreenRect.Height, dc1, mScreenRect.Left, mScreenRect.Top, cRasterOp_SrcCopy);
// Remember to release the dc's, otherwise problems down the road
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
// return bitmap
return bmp;
}
#endregion
#region gdi32.dll
[DllImport("gdi32")]
private static extern IntPtr CreateDC(string lpDriverName, string lpDeviceName, int lpOutput, int lpInitData);
[DllImport("gdi32")]
private static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int width, int height, IntPtr hdcSrc, int xSrc, int ySrc, int dwRop);
#endregion
}
}
0
不错。不要忘记,Vista有桌面窗口管理器来创建半透明窗口(又名Areo)http://msdn.microsoft.com/en-us/magazine/cc163435.aspx
相关问题
- 1. 如何使用透明图像作为透明winform的背景?
- 2. 透明图像搞乱透明图像
- 3. 透明PNG图像与TImageList
- 4. 透明与Python图像库
- 5. 透明图像
- 6. 透明背景透明图像问题
- 7. 伪透明图像
- 8. CSS图像透明
- 9. android图像透明
- 10. 非透明图像
- 11. 透明或不透明的背景与css中的图像
- 12. SpriteKit碰撞检测与透明图像
- 13. 透明Jbutton将与背景图像
- 14. imagecopymerge不与部分透明的图像
- 15. 背景图像,但与不透明css
- 16. 透明度问题与PNG图像
- 17. OpenCV warp问题与透明图像
- 18. 不透明图像悬停与jQuery
- 19. Alpha与两个透明图像混合
- 20. 在ImageView中的不透明图像上的透明图像
- 21. 将透明图像复制到另一个透明图像
- 22. 合并两个不透明图像以获得透明图像
- 23. 在另一个透明图像上移动透明图像
- 24. 绘制透明图像
- 25. Internet Explorer:半透明图像
- 26. CSS3渐变图像透明
- 27. 图像背景透明GIMP
- 28. FXML图像透明度
- 29. imagick图像水印透明
- 30. iOS着色透明图像
的确如此,但我需要一些向后兼容Windows XP的东西。 – 2009-09-02 18:50:34