当前位置: 首页>>代码示例>>C#>>正文


C# Bitmap.GetHbitmap方法代码示例

本文整理汇总了C#中Bitmap.GetHbitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetHbitmap方法的具体用法?C# Bitmap.GetHbitmap怎么用?C# Bitmap.GetHbitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bitmap的用法示例。


在下文中一共展示了Bitmap.GetHbitmap方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CREDUI_INFO

 public CREDUI_INFO(IntPtr hwndOwner, string caption, string message, Bitmap banner)
 {
     cbSize = Marshal.SizeOf(typeof(CREDUI_INFO));
     hwndParent = hwndOwner;
     pszCaptionText = caption;
     pszMessageText = message;
     hbmBanner = banner != null ? banner.GetHbitmap() : IntPtr.Zero;
 }
开发者ID:tablesmit,项目名称:task-scheduler-managed-wrapper,代码行数:8,代码来源:CREDUI.cs

示例2: ResizeImageFile

    protected static System.Drawing.Image ResizeImageFile(System.Drawing.Image img)
    {
        using (img)
        {
            Size newSize = CalculateNewImageSize(img.Size);
            using (Bitmap newImage = new Bitmap(newSize.Width, newSize.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555))
            {
                using (Graphics canvas = Graphics.FromImage(newImage))
                {
                    canvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    canvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    canvas.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                    canvas.DrawImage(img, new Rectangle(new Point(0,0), newSize));

                    System.IO.MemoryStream m = new System.IO.MemoryStream();
                    return (System.Drawing.Image.FromHbitmap(newImage.GetHbitmap()));

                }

            }

        }
    }
开发者ID:vsrz,项目名称:NellyBrandt,代码行数:23,代码来源:PhotoUpload.aspx.cs

示例3: CustomCursor

            internal CustomCursor(Bitmap bitmap, int x, int y)
            {
                ICONINFO iconInfo = new ICONINFO();
                iconInfo.fIcon = false;
                iconInfo.xHotspot = x;
                iconInfo.yHotspot = y;
                iconInfo.hbmMask = bitmap.GetHbitmap();
                iconInfo.hbmColor = bitmap.GetHbitmap();

                handle = CreateIconIndirect(ref iconInfo);
                cursor = new Cursor(handle);
            }
开发者ID:ChrisH4rding,项目名称:xenadmin,代码行数:12,代码来源:VNCGraphicsClient.cs

示例4: GetHbitmapFromImage

 /// <summary>
 /// Gets an HBITMAP from any image.
 /// </summary>
 /// <param name="image">The image to get an HBITMAP from.</param>
 /// <returns>An HBITMAP pointer.</returns>
 /// <remarks>
 /// The caller is responsible to call DeleteObject on the HBITMAP.
 /// </remarks>
 private static IntPtr GetHbitmapFromImage(Image image)
 {
     if (image is Bitmap)
     {
         return ((Bitmap) image).GetHbitmap();
     }
     else
     {
         Bitmap bmp = new Bitmap(image);
         return bmp.GetHbitmap();
     }
 }
开发者ID:applejian,项目名称:cyberduck,代码行数:20,代码来源:DragDropLib.cs

示例5: SetBitmap

    public void SetBitmap(Bitmap bitmap, byte opacity)
    {
        if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");

        IntPtr screenDc = Win32.GetDC(IntPtr.Zero);
        IntPtr memDc = Win32.CreateCompatibleDC(screenDc);
        IntPtr hBitmap = IntPtr.Zero;
        IntPtr oldBitmap = IntPtr.Zero;

        try
        {
            hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
            oldBitmap = Win32.SelectObject(memDc, hBitmap);

            Win32.Size size = new Win32.Size(bitmap.Width, bitmap.Height);
            Win32.Point pointSource = new Win32.Point(0, 0);
            Win32.Point topPos = new Win32.Point(Left, Top);
            Win32.BLENDFUNCTION blend = new Win32.BLENDFUNCTION();
            blend.BlendOp = Win32.AC_SRC_OVER;
            blend.BlendFlags = 0;
            blend.SourceConstantAlpha = opacity;
            blend.AlphaFormat = Win32.AC_SRC_ALPHA;

            Win32.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, Win32.ULW_ALPHA);
        }
        finally
        {
            Win32.ReleaseDC(IntPtr.Zero, screenDc);
            if (hBitmap != IntPtr.Zero)
            {
                Win32.SelectObject(memDc, oldBitmap);
                Win32.DeleteObject(hBitmap);
            }
            Win32.DeleteDC(memDc);
        }
    }
开发者ID:Celtc,项目名称:TaskMonitor,代码行数:37,代码来源:LogoForm.cs

示例6: SetBitmap

    /// <para>Changes the current bitmap with a custom opacity level.  Here is where all happens!</para>
    public void SetBitmap(Bitmap bitmap, byte opacity)
    {
        if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");

        // The ideia of this is very simple,
        // 1. Create a compatible DC with screen;
        // 2. Select the bitmap with 32bpp with alpha-channel in the compatible DC;
        // 3. Call the UpdateLayeredWindow.

        IntPtr screenDc = Win32.GetDC(IntPtr.Zero);
        IntPtr memDc = Win32.CreateCompatibleDC(screenDc);
        IntPtr hBitmap = IntPtr.Zero;
        IntPtr oldBitmap = IntPtr.Zero;

        try {
            hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));  // grab a GDI handle from this GDI+ bitmap
            oldBitmap = Win32.SelectObject(memDc, hBitmap);

            Win32.Size size = new Win32.Size(bitmap.Width, bitmap.Height);
            Win32.Point pointSource = new Win32.Point(0, 0);
            Win32.Point topPos = new Win32.Point(Left, Top);
            Win32.BLENDFUNCTION blend = new Win32.BLENDFUNCTION();
            blend.BlendOp             = Win32.AC_SRC_OVER;
            blend.BlendFlags          = 0;
            blend.SourceConstantAlpha = opacity;
            blend.AlphaFormat         = Win32.AC_SRC_ALPHA;

            Win32.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, Win32.ULW_ALPHA);
        }
        finally {
            Win32.ReleaseDC(IntPtr.Zero, screenDc);
            if (hBitmap != IntPtr.Zero) {
                Win32.SelectObject(memDc, oldBitmap);
                //Windows.DeleteObject(hBitmap); // The documentation says that we have to use the Windows.DeleteObject... but since there is no such method I use the normal DeleteObject from Win32 GDI and it's working fine without any resource leak.
                Win32.DeleteObject(hBitmap);
            }
            Win32.DeleteDC(memDc);
        }
    }
开发者ID:SudoMike,项目名称:SudoFont,代码行数:41,代码来源:PerPixelAlphaForm.cs

示例7: SetDragImage

        /// <summary>
        /// Sets the drag image.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the drag image on.</param>
        /// <param name="image">The drag image.</param>
        /// <param name="cursorOffset">The location of the cursor relative to the image.</param>
        private static void SetDragImage(this IDataObject dataObject, Bitmap bitmap, Point cursorOffset)
        {
            ShDragImage shdi = new ShDragImage();

            Win32Size size;
            size.cx = bitmap.Width;
            size.cy = bitmap.Height;
            shdi.sizeDragImage = size;

            Win32Point wpt;
            wpt.x = (int)cursorOffset.X;
            wpt.y = (int)cursorOffset.Y;
            shdi.ptOffset = wpt;

            shdi.crColorKey = DrawingColor.Magenta.ToArgb();

            // This HBITMAP will be managed by the DragDropHelper
            // as soon as we pass it to InitializeFromBitmap. If we fail
            // to make the hand off, we'll delete it to prevent a mem leak.
            IntPtr hbmp = bitmap.GetHbitmap();
            shdi.hbmpDragImage = hbmp;

            try
            {
                IDragSourceHelper sourceHelper = (IDragSourceHelper)new DragDropHelper();

                try
                {
                    sourceHelper.InitializeFromBitmap(ref shdi, (ComIDataObject)dataObject);
                }
                catch (NotImplementedException ex)
                {
                    throw new Exception("A NotImplementedException was caught. This could be because you forgot to construct your DataObject using a DragDropLib.DataObject", ex);
                }
            }
            catch
            {
                // We failed to initialize the drag image, so the DragDropHelper
                // won't be managing our memory. Release the HBITMAP we allocated.
                DeleteObject(hbmp);
            }
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:48,代码来源:WpfDataObjectExtensions.cs

示例8: PaintNative

    private void PaintNative(Bitmap bitmap, byte opacity)
    {
        IntPtr hdcDestination = NativeMethods.GetDC(IntPtr.Zero);
        IntPtr hdcSource = NativeMethods.CreateCompatibleDC(hdcDestination);
        IntPtr hdcBitmap = IntPtr.Zero;
        IntPtr previousBitmap = IntPtr.Zero;
        try
        {
            hdcBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
            previousBitmap = NativeMethods.SelectObject(hdcSource, hdcBitmap);

            NativeMethods.SIZE size = new NativeMethods.SIZE(bitmap.Width, bitmap.Height);
            NativeMethods.POINT source = new NativeMethods.POINT(0, 0);
            NativeMethods.POINT destination = new NativeMethods.POINT(Left, Top);
            NativeMethods.BLENDFUNCTION blend = new NativeMethods.BLENDFUNCTION();

            blend.BlendOp = NativeMethods.AC_SRC_OVER;
            blend.BlendFlags = 0;
            blend.SourceConstantAlpha = opacity;
            blend.AlphaFormat = NativeMethods.AC_SRC_ALPHA;

            NativeMethods.UpdateLayeredWindow(
                Handle,
                hdcDestination,
                ref destination,
                ref size,
                hdcSource,
                ref source,
                0,
                ref blend,
                2);
        }
        catch (Exception)
        {
            return;
        }
        finally
        {
            NativeMethods.ReleaseDC(IntPtr.Zero, hdcDestination);
            if (hdcBitmap != IntPtr.Zero)
            {
                NativeMethods.SelectObject(hdcSource, previousBitmap);
                NativeMethods.DeleteObject(hdcBitmap);
            }
            NativeMethods.DeleteDC(hdcSource);
        }
    }
开发者ID:vantruc,项目名称:skimpt,代码行数:47,代码来源:genericLayeredForm.cs

示例9: SetBits

    public void SetBits(Bitmap bitmap, byte opacity)
    {
        if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
            throw new ApplicationException("The bitmap must be 32 bits per pixel with an alpha channel.");

        IntPtr oldBits = IntPtr.Zero;
        IntPtr screenDC = Win32.GetDC(IntPtr.Zero);
        IntPtr hBitmap = IntPtr.Zero;
        IntPtr memDc = Win32.CreateCompatibleDC(screenDC);
        Win32.POINT topLoc = new Win32.POINT(Left, Top);
        Win32.SIZE bitMapSize = new Win32.SIZE(bitmap.Width, bitmap.Height);
        Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION();
        Win32.POINT srcLoc = new Win32.POINT(0, 0);
        blendFunc.BlendOp = Win32.AC_SRC_OVER;
        blendFunc.SourceConstantAlpha = opacity;
        blendFunc.AlphaFormat = Win32.AC_SRC_ALPHA;
        blendFunc.BlendFlags = 0;

        try
        {
            hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
            oldBits = Win32.SelectObject(memDc, hBitmap);
            Win32.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, Win32.ULW_ALPHA);
        }
        finally
        {
            if (hBitmap != IntPtr.Zero)
            {
                Win32.SelectObject(memDc, oldBits);
                Win32.DeleteObject(hBitmap);
            }
            Win32.ReleaseDC(IntPtr.Zero, screenDC);
            Win32.DeleteDC(memDc);
        }
    }
开发者ID:jorik041,项目名称:Athena-NeuroPlay,代码行数:35,代码来源:AlphaForm.cs


注:本文中的Bitmap.GetHbitmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。