Beispiel #1
0
        /// <summary>
        /// .NET FrameworkのBitmapをベースにTexture化する。
        /// </summary>
        /// <remarks>これがあれば、.NETのGraphics等で描画したものを
        /// テクスチャー化して描画できる。ただし、内部的には何度もメモリ
        /// コピーを行なう必要があるためあまり速くはない。なるべくなら動的には
        /// 行なわないほうが良い。</remarks>
        /// <code>
        ///		Bitmap bmp = new Bitmap(100, 100);
        ///		Graphics g = Graphics.FromImage(bmp);
        ///		g.DrawLine(new Pen(Color.Aqua, 10), 0, 0, 100, 100);
        ///		GlTexture txt = new GlTexture();
        ///		txt.SetBitmap(bmp);
        ///		g.Dispose();
        ///		scr.Blt(txt, 100, 100);
        ///		txt.Dispose();
        /// </code>
        /// <param name="bmp"></param>
        /// <returns></returns>
        public YanesdkResult SetBitmap(global::System.Drawing.Bitmap bmp)
        {
            //	転送元と転送先のサイズが同じで転送先がα付きのときは
            //	glTextureSubImageで転送したほうが良いのだが
            //	そんなに再々呼び出すことはないので、このままにしておこう…。

            Surface       surface;
            YanesdkResult result = BitmapHelper.BitmapToSurface(bmp, out surface);

            if (result != YanesdkResult.NoError)
            {
                return(result);
            }
            this.SetSurface(surface);
            surface.Dispose();

            return(YanesdkResult.NoError);
        }
Beispiel #2
0
        /// <summary>
        /// ウィンドウのクライアント領域をキャプチャする。
        /// 失敗時はnullが返る。
        ///	Form.Handleを渡すべし。
        ///
        /// Windows専用。
        /// </summary>
        public static Surface FromHandle(IntPtr hwnd)
        {
            // Windows専用である
            if (System.Platform.PlatformID != Yanesdk.System.PlatformID.Windows)
            {
                throw new YanesdkException(YanesdkResult.NotImplemented);
            }

            RECT rect;

            GetClientRect(hwnd, out rect);

            using (Bitmap bmp = new Bitmap(rect.right - rect.left, rect.bottom - rect.top))
            {
                // HDCを取得してキャプチャ
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    IntPtr hdc = GetDC(hwnd);
                    int    rop = SRCCOPY;
                    if (4 < Environment.OSVersion.Version.Major)
                    {
                        // layerd windowもキャプチャするにはこれも指定する必要がある。
                        rop |= CAPTUREBLT;
                    }
                    BitBlt(g.GetHdc(), 0, 0, bmp.Width, bmp.Height, hdc, 0, 0, rop);
                    ReleaseDC(hwnd, hdc);
                }
                // BitmapからSurfaceを作成
                Surface surface;
                if (BitmapHelper.BitmapToSurface(bmp, out surface) != YanesdkResult.NoError)
                {
                    return(null);
                }
                return(surface);
            }
        }