2009-05-13 2 views
1

トランスペアレンシーをサポートするコンパクトフレームワークコントロールを設計していますが、このAPIでプラットフォームを呼び出すだけで、すべての機能が実行されます。コンパクトフレームワークコントロールの設計時にアルファブレンディングを行う方法

[DllImport("coredll.dll")] 
    extern public static Int32 AlphaBlend(IntPtr hdcDest, Int32 xDest, Int32 yDest, Int32 cxDest, Int32 cyDest, IntPtr hdcSrc, Int32 xSrc, Int32 ySrc, Int32 cxSrc, Int32 cySrc, BlendFunction blendFunction); 

明らかに、 "coredll.dll"の呼び出しは、デスクトップデザイン時の経験では機能しません。今のところ、ペインティングが発生したとき、コントロールが設計されていることを検出して、透明性。私はより良いデザインタイムエクスペリエンスを提供し、Visual Studio Designerで同じ透明性を示すことができるようにしたいと考えています。

私はこのプラットフォーム呼び出し作ってみた:

[DllImport("gdi32.dll", EntryPoint = "GdiAlphaBlend")] 
    public static extern bool AlphaBlendDesktop(IntPtr hdcDest, int nXOriginDest, int nYOriginDest, 
     int nWidthDest, int nHeightDest, 
     IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, 
     BlendFunction blendFunction); 

をそれがtrueを返したが、結果は全く何もありませんが、設計時のビューに描かれています。

どのような考えですか?

答えて

0

申し訳ありませんが、あなたの質問に正確には答えていませんが、既にアルファブレンディングを行っている.Net Compact FrameworkのUIフレームワークをチェックしてください。

http://code.msdn.microsoft.com/uiframework

+0

これは決してすべての答えではなく、さらには彼の質問に答える試みでもあります。彼は既にデバイスに取り組んでいます。同じようにデザイナーでレンダリングしたいだけです。 – ctacke

+1

UI Frameworkは彼がやろうとしていることを行います(さらに多くのことを行います)、ソースコードとともに出荷されます。 ここでは役に立たないのは、あなたの回答です。 –

+0

私はすでにUIフレームワークを見てきましたが、私が解決しようとしている問題は、言及されているようには役に立ちません。 UIフレームワークは、アルファブレンディングを使用するコンパクトなフレームワークコントロールのデザイナーサポートの問題に対処していません。おそらく私の質問はもっと明確になるだろうか? –

2

これは、AlphaBlend操作を実行するために、設計者をだますために私のために働きました。

// PixelFormatIndexed = 0x00010000, // Indexes into a palette 
// PixelFormatGDI = 0x00020000, // Is a GDI-supported format 
// PixelFormatAlpha = 0x00040000, // Has an alpha component 
// PixelFormatPAlpha = 0x00080000, // Pre-multiplied alpha 
// PixelFormatExtended = 0x00100000, // Extended color 16 bits/channel 
// PixelFormatCanonical = 0x00200000, 
// PixelFormat32bppARGB = (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical), 

// cheat the design time to create a bitmap with an alpha channel 
using (Bitmap bmp = new Bitmap(image.Width, image.Height, (PixelFormat) 
              PixelFormat32bppARGB)) 
{ 
    // copy the original image 
    using(Graphics g = Graphics.FromImage(bmp)) 
    { 
    g.DrawImage(image,0,0); 
    } 

    // Lock the bitmap's bits. 
    Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); 
    System.Drawing.Imaging.BitmapData bmpData = 
    bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, 
          (PixelFormat)PixelFormat32bppARGB); 

    // Get the address of the first line. 
    IntPtr ptr = bmpData.Scan0; 

    // Declare an array to hold the bytes of the bitmap. 
    // This code is specific to a bitmap with 32 bits per pixels. 
    int bytes = bmp.Width * bmp.Height * 4; 
    byte[] argbValues = new byte[bytes]; 

    // Copy the ARGB values into the array. 
    System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, bytes); 

    // Set every alpha value to the given transparency. 
    for (int counter = 3; counter < argbValues.Length; counter += 4) 
          argbValues[counter] = transparency; 

    // Copy the ARGB values back to the bitmap 
    System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, ptr, bytes); 

    // Unlock the bits. 
    bmp.UnlockBits(bmpData); 

    gx.DrawImage(bmp, x, y); 
} 
+0

恐ろしく!私がこれを解決しようとして以来、それは私が検証するまでには時間がかかりましたが、それはずっと長かったですが、それは素晴らしい解決策のように見えます。ありがとうございました。 –

関連する問題