我有一個圖像(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