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


C# Bitmap.GetHbitmap方法代码示例

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


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

示例1: FormDisplay

		public FormDisplay(Root root)
		{
			Root = root;
			InitializeComponent();

			this.Left = SystemInformation.VirtualScreen.Left;
			this.Top = SystemInformation.VirtualScreen.Top;
			int targetbottom = 0;
			foreach (Screen screen in Screen.AllScreens)
			{
				if (screen.WorkingArea.Bottom > targetbottom)
					targetbottom = screen.WorkingArea.Bottom;
			}
			int virwidth = SystemInformation.VirtualScreen.Width;
			this.Width = virwidth;
			this.Height = targetbottom - this.Top;

			Bitmap InitCanvus = new Bitmap(this.Width, this.Height);
			Canvus = InitCanvus.GetHbitmap(Color.FromArgb(0));
			OneStrokeCanvus = InitCanvus.GetHbitmap(Color.FromArgb(0));
			//BlankCanvus = InitCanvus.GetHbitmap(Color.FromArgb(0));

			IntPtr screenDc = GetDC(IntPtr.Zero);
			canvusDc = CreateCompatibleDC(screenDc);
			SelectObject(canvusDc, Canvus);
			onestrokeDc = CreateCompatibleDC(screenDc);
			SelectObject(onestrokeDc, OneStrokeCanvus);
			//blankcanvusDc = CreateCompatibleDC(screenDc);
			//SelectObject(blankcanvusDc, BlankCanvus);
			gCanvus = Graphics.FromHdc(canvusDc);
			gCanvus.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
			gOneStrokeCanvus = Graphics.FromHdc(onestrokeDc);
			gOneStrokeCanvus.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
			if (Root.AutoScroll)
			{
				hScreenBitmap = InitCanvus.GetHbitmap(Color.FromArgb(0));
				memscreenDc = CreateCompatibleDC(screenDc);
				SelectObject(memscreenDc, hScreenBitmap);
				screenbits = new byte[50000000];
				lastscreenbits = new byte[50000000];
			}
			ReleaseDC(IntPtr.Zero, screenDc);
			InitCanvus.Dispose();

			//this.DoubleBuffered = true;

			gpButtonsImage = new Bitmap(2400, 100);
			TransparentBrush = new SolidBrush(Color.Transparent);
			SemiTransparentBrush = new SolidBrush(Color.FromArgb(120, 255, 255, 255));


			ToTopMostThrough();
		}
开发者ID:geovens,项目名称:gInk,代码行数:53,代码来源:FormDisplay.cs

示例2: BorderPaint

        public BorderPaint(Bitmap image, bool imageIsOwned, BorderPaintMode flags, params Rectangle[] slices)
        {
            _flags = flags;
            _slices = slices;
            _bitmap = image;
            _imageIsOwned = imageIsOwned;

            if (IsFlagSet(flags, BorderPaintMode.GDI))
            {
                _hBitmap = image.GetHbitmap();
            }
            else if (IsFlagSet(flags, BorderPaintMode.Cached))
            {
                _sliceCache = new Bitmap[SLICECOUNT];
                for (int i = 0; i < SLICECOUNT; i++)
                {
                    if (slices[i].Width > 0 && slices[i].Height > 0)
                    {
                        Bitmap cachedSlice = new Bitmap(slices[i].Width, slices[i].Height, image.PixelFormat);
                        using (Graphics g = Graphics.FromImage(cachedSlice))
                            g.DrawImage(image, new Rectangle(0, 0, slices[i].Width, slices[i].Height), slices[i], GraphicsUnit.Pixel);
                        _sliceCache[i] = cachedSlice;
                    }
                }
            }
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:26,代码来源:BorderPaint.cs

示例3: Convert

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //convert GDI+ bitmap to image source
            Bitmap bmp = value as Bitmap;
            if (bmp != null)
            {
                BitmapSource bitmapsource = null;
                try
                {
                    bitmapsource = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero,
                                                                                      Int32Rect.Empty,
                                                                                      BitmapSizeOptions.FromEmptyOptions
                                                                                          ());
                }
                catch (Exception exp)
                {
                    Bitmap tempbmp = new Bitmap(32, 32);
                    Graphics g = Graphics.FromImage(tempbmp);
                    g.Clear(Color.Magenta);
                    bitmapsource = Imaging.CreateBitmapSourceFromHBitmap(tempbmp.GetHbitmap(Color.Magenta),
                        IntPtr.Zero, Int32Rect.Empty,
                        BitmapSizeOptions.FromEmptyOptions());

                }
                return bitmapsource;
            }
            return null;
        }
开发者ID:BCProgramming,项目名称:BCJobClock,代码行数:28,代码来源:BitmapConverter.cs

示例4: Tile

      public Tile(Image image, TileCoordinate tile, RenderMode mode)
      {
         this.tile = tile;
         if(image != null)
         {
            this.mode = mode;

            switch(mode)
            {
               case RenderMode.GDI:
               {
                  using(Bitmap bitmap = new Bitmap(image))
                  {
                     this.ptrHbitmap = bitmap.GetHbitmap();
                  }
               }
               break;

               case RenderMode.GDI_PLUS:
               {
                  this.image = image;
               }
               break;
            }
         }
      }
开发者ID:gipasoft,项目名称:Sfera,代码行数:26,代码来源:Tile.cs

示例5: GetHbitmap

		public void GetHbitmap ()
		{
			Bitmap b = new Bitmap (10, 10);
			try {
				Assert.IsTrue (b.GetHbitmap () != IntPtr.Zero, "GetHbitmap");
			}
			catch (NotImplementedException) {
				// not available on Mono
			}
			try {
				Assert.IsTrue (b.GetHbitmap (Color.Aqua) != IntPtr.Zero, "GetHbitmap(Color)");
			}
			catch (NotImplementedException) {
				// not available on Mono
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:BitmapCas.cs

示例6: Convert

        /// <summary>
        /// Converts an System.Drawing.Image to a BitmapSource.
        /// </summary>
        /// <param name="value">Image to convert.</param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns>Submitted value as a Bitmapsource.</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Image myImage = value as Image;
            BitmapSource bitmapSource = null;
            if (myImage != null)
            {
                IntPtr bmpPt = IntPtr.Zero;

                try
                {
                    var bitmap = new Bitmap(myImage);
                    bmpPt = bitmap.GetHbitmap();
                    bitmapSource =
                     System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                           bmpPt,
                           IntPtr.Zero,
                           Int32Rect.Empty,
                           BitmapSizeOptions.FromEmptyOptions());

                    bitmapSource.Freeze();
                }
                finally
                {
                    if (bmpPt != IntPtr.Zero)
                        DeleteObject(bmpPt);
                }
            }

            return bitmapSource;
        }
开发者ID:Displayedd,项目名称:PrismWpfApplication,代码行数:38,代码来源:ImageToBitmapsourceConverter.cs

示例7: Fill_Image_Buffer

        public static byte[,,] Fill_Image_Buffer(Bitmap bmp, IProgress progress, ICurrentOperation operation)
        {
            if (operation != null)
                operation.SetOperation(CurrentOperation.FillImageBuffer);

            Point originalSize = GetActualDimension(new Point(bmp.Width, bmp.Height));
            byte[,,] Bitmap_Buffer = new byte[originalSize.X,originalSize.Y, 3];

            IntPtr hbmScreen = IntPtr.Zero;
            IntPtr hBmpInput = bmp.GetHbitmap();

            InteropGDI.BITMAP bmpInput = new InteropGDI.BITMAP();
            InteropGDI.GetObject(hBmpInput, 24, ref bmpInput);
            InteropGDI.BITMAPINFOHEADER bi;

            bi.biSize = 40;
            bi.biWidth = bmpInput.bmWidth;
            bi.biHeight = -bmpInput.bmHeight; // Negative to reverse the scan order.
            bi.biPlanes = 1;
            bi.biBitCount = 32;
            bi.biCompression = (uint)InteropGDI.BMP_Compression_Modes.BI_RGB;
            bi.biSizeImage = 0;
            bi.biXPelsPerMeter = 0;
            bi.biYPelsPerMeter = 0;
            bi.biClrUsed = 0;
            bi.biClrImportant = 0;

            ulong bitmapLengthBytes = (ulong)(((bmpInput.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpInput.bmHeight);

            byte[] bitmap_array = new byte[bitmapLengthBytes];

            IntPtr hdcWindow = InteropGDI.CreateCompatibleDC(IntPtr.Zero);

            InteropGDI.GetDIBits(hdcWindow, hBmpInput, (uint)0,
                (uint)bmpInput.bmHeight,
                bitmap_array,
                ref bi, (uint)InteropGDI.DIB_COLORS.DIB_RGB_COLORS);

            int k = 0, wd = bmpInput.bmWidth, ht = bmpInput.bmHeight;

            for (int j = 0; j < ht; j++)
            {
                if (progress != null)
                    progress.SetProgress((int)bitmapLengthBytes, k);

                for (int i = 0; i < wd; i++)
                {
                    Bitmap_Buffer[i, j, 2] = bitmap_array[k++];
                    Bitmap_Buffer[i, j, 1] = bitmap_array[k++];
                    Bitmap_Buffer[i, j, 0] = bitmap_array[k++];
                    k++;
                }
            }

            InteropGDI.DeleteObject(hdcWindow);
            InteropGDI.DeleteObject(hbmScreen);
            InteropGDI.DeleteObject(hBmpInput);

            return Bitmap_Buffer;
        }
开发者ID:b9chris,项目名称:ArpanJpegEncoder,代码行数:60,代码来源:Utils.cs

示例8: OpenButton_OnClick

        //打开图片
        private void OpenButton_OnClick(object sender, RoutedEventArgs e)
        {
            var openFile = new OpenFileDialog
            {
                InitialDirectory = Environment.CurrentDirectory,
                Filter = "JPEG图片|*.jpg|PNG图片|*.png",
                RestoreDirectory = false,
                FilterIndex = 1
            };
            if (openFile.ShowDialog() != true) return;
            _srcImage?.Dispose();
            _dstImage?.Dispose();
            _dstImage = null;
            GC.Collect();
            //强行回收内存
            _srcImage = new Bitmap(openFile.FileName, false);

            //将源图像转化为BitmapSource,并用Image控件显示
            var ip = _srcImage.GetHbitmap();
            var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());
            Rescale.CenterX = 0;
            Rescale.CenterY = 0;
            Rescale.ScaleX = Rescale.ScaleY = 1;
            CurrentImage.Source = bitmapSource;
           
        }
开发者ID:chinyuchao,项目名称:ImageConvert,代码行数:28,代码来源:MainWindow.xaml.cs

示例9: DisplayAndShowIcon

        /// <summary>
        /// The display and show icon.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        public void DisplayAndShowIcon(string message)
        {
            var b =
                new Bitmap(
                    @"E:\Development\SonarQube\VssonarExtension\VSSonarQubeExtension\VSSonarExtension\PackageImplementation\Resources\sonariconsource.bmp");
            IntPtr hdc = IntPtr.Zero;
            hdc = b.GetHbitmap();

            object hdcObject = hdc;

            vssStatusBar.Bar.Animation(1, ref hdcObject);

            Thread.Sleep(10000);

            vssStatusBar.Bar.Animation(0, ref hdcObject);
            DeleteObject(hdc);

            return;

            object icon = Constants.SBAI_Build;
            vssStatusBar.dte.StatusBar.Animate(true, icon);

            // this.Bar.Animation(1, ref icon);
            vssStatusBar.dte.StatusBar.Text = message;

            // this.Bar.SetText(message);
            vssStatusBar.dte.StatusBar.Animate(false, icon);

            // this.Bar.Animation(0, ref icon);
            vssStatusBar.dte.StatusBar.Text = "Build Succeeded";
        }
开发者ID:kanchanachalla,项目名称:VSSonarQubeExtension,代码行数:37,代码来源:IVSStatusBar.cs

示例10: SetBitmap

        /// <summary>
        /// Set overlay bitmap with a custom opacity level.
        /// </summary>
        public void SetBitmap(Bitmap bitmap, byte opacity)
        {
            if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
                throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");

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

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

                var size = new Win32.Size(bitmap.Width, bitmap.Height);
                var pointSource = new Win32.Point(0, 0);
                var topPos = new Win32.Point(Left, Top);
                var blend = new Win32.BLENDFUNCTION{
                    BlendOp = Win32.AC_SRC_OVER,
                    BlendFlags = 0,
                    SourceConstantAlpha = opacity,
                    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:i-e-b,项目名称:WindowsJedi,代码行数:37,代码来源:OverlayForm.cs

示例11: ToBitmapSource

        //Code within this region is credited to user "Alastair Pitts" in the thread http://stackoverflow.com/questions/94456/load-a-wpf-bitmapimage-from-a-system-drawing-bitmap
        /// <summary>
        /// Converts a <see cref="System.Drawing.Bitmap"/> into a WPF <see cref="BitmapSource"/>.
        /// </summary>
        /// <remarks>Uses GDI to do the conversion. Hence the call to the marshalled DeleteObject.
        /// </remarks>
        /// <param name="source">The source bitmap.</param>
        /// <returns>A BitmapSource</returns>
        public static BitmapSource ToBitmapSource(Bitmap source)
        {
            BitmapSource bitSrc = null;

            var hBitmap = source.GetHbitmap();

            try
            {
                bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    hBitmap,
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());
            }
            catch (Win32Exception)
            {
                bitSrc = null;
            }
            finally
            {
                NativeMethods.DeleteObject(hBitmap);
            }

            return bitSrc;
        }
开发者ID:FatherFoxxy,项目名称:CSharpTradeOffers,代码行数:33,代码来源:MainWindow.xaml.cs

示例12: Freeze

        // freeze the form
        public void Freeze()
        {
            // Remember we have frozen the form once more
            // Do nothing if it was already frozen
            if (++FreezeCount > 1)
                return;

            Rectangle rect = form.ClientRectangle;
            if (rect.IsEmpty || form.WindowState == FormWindowState.Minimized)
                return;

            Point topLeft = form.PointToScreen(new Point(rect.Left, rect.Top));

            // Create a PictureBox that resizes with its contents
            pictureBox = new PictureBox();
            pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;

            // create a bitmap as large as the form's client area and with same color depth
            using (Graphics frmGraphics = form.CreateGraphics()) {
                Bitmap bitmap = new Bitmap(rect.Width, rect.Height, frmGraphics);
                hBitmap = bitmap.GetHbitmap();
                pictureBox.Image = Image.FromHbitmap(hBitmap);
            }

            // copy the screen contents, from the form's client area to the hidden bitmap
            using (Graphics picGraphics = Graphics.FromImage(pictureBox.Image)) {
                picGraphics.CopyFromScreen(topLeft, Point.Empty, rect.Size, CopyPixelOperation.SourceCopy);
            }

            // Display the bitmap in the picture box, and show the picture box in front of all other controls
            form.Controls.Add(pictureBox);
            pictureBox.BringToFront();
        }
开发者ID:GiGatR00n,项目名称:AionParsers,代码行数:34,代码来源:FormFreezer.cs

示例13: btnProcess_Click

        private void btnProcess_Click(object sender, RoutedEventArgs e)
        {
            double[,] matrix = new double[3, 3];

            matrix[0, 0] = double.Parse(txt00.Text, CultureInfo.InvariantCulture);
            matrix[0, 1] = double.Parse(txt01.Text, CultureInfo.InvariantCulture);
            matrix[0, 2] = double.Parse(txt02.Text, CultureInfo.InvariantCulture);
            matrix[1, 0] = double.Parse(txt10.Text, CultureInfo.InvariantCulture);
            matrix[1, 1] = double.Parse(txt11.Text, CultureInfo.InvariantCulture);
            matrix[1, 2] = double.Parse(txt12.Text, CultureInfo.InvariantCulture);
            matrix[2, 0] = double.Parse(txt20.Text, CultureInfo.InvariantCulture);
            matrix[2, 1] = double.Parse(txt21.Text, CultureInfo.InvariantCulture);
            matrix[2, 2] = double.Parse(txt22.Text, CultureInfo.InvariantCulture);

            GenericFilter sharpen = new GenericFilter();
            sharpen.FilterName = "Sharpen";
            sharpen.FilterMatrix = matrix;
            //sharpen.FilterMatrix = new double[,] {{ 0.0,  0.2, 0.0 },
            //                                      { 0.2,  0.2, 0.2 },
            //                                      { 0.0,  0.2, 0.2 }};

            resultImage = previewImage.ConvolutionFilter(sharpen);

            image.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(resultImage.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            previewImage = resultImage;
        }
开发者ID:carloscaicedos,项目名称:ImageFilters,代码行数:27,代码来源:MainWindow.xaml.cs

示例14: BitmapSourceFromBitmap

 public static BitmapSource BitmapSourceFromBitmap(Bitmap bitmap)
 {
     BitmapSource bitSrc = null;
     var hBitmap = bitmap.GetHbitmap();
     bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
     return bitSrc;
 }
开发者ID:jahe,项目名称:AP-HA,代码行数:7,代码来源:DataProcessor.cs

示例15: CreateCursor

        /// <summary>
        ///     カーソルを作成する
        /// </summary>
        /// <param name="bitmap">カーソル画像</param>
        /// <param name="xHotSpot">ホットスポットのX座標</param>
        /// <param name="yHotSpot">ホットスポットのY座標</param>
        /// <returns>作成したカーソル</returns>
        public static Cursor CreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot)
        {
            Bitmap andMask = new Bitmap(bitmap.Width, bitmap.Height);
            Bitmap xorMask = new Bitmap(bitmap.Width, bitmap.Height);
            Color transparent = bitmap.GetPixel(bitmap.Width - 1, bitmap.Height - 1);
            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    Color pixel = bitmap.GetPixel(x, y);
                    if (pixel == transparent)
                    {
                        andMask.SetPixel(x, y, Color.White);
                        xorMask.SetPixel(x, y, Color.Transparent);
                    }
                    else
                    {
                        andMask.SetPixel(x, y, Color.Black);
                        xorMask.SetPixel(x, y, pixel);
                    }
                }
            }

            IntPtr hIcon = bitmap.GetHicon();
            IconInfo info = new IconInfo();
            NativeMethods.GetIconInfo(hIcon, ref info);
            info.xHotspot = xHotSpot;
            info.yHotspot = yHotSpot;
            info.hbmMask = andMask.GetHbitmap();
            info.hbmColor = xorMask.GetHbitmap();
            info.fIcon = false;
            hIcon = NativeMethods.CreateIconIndirect(ref info);
            return new Cursor(hIcon);
        }
开发者ID:nkodama,项目名称:HoI2Editor,代码行数:41,代码来源:CursorFactory.cs


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