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


C# System.Drawing.Bitmap.GetHbitmap方法代码示例

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


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

示例1: convert

 public static BitmapSource convert(System.Drawing.Bitmap imageToConvert)
 {
     var bitmap = new System.Drawing.Bitmap(imageToConvert);
     BitmapSource convertedImage = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
     bitmap.Dispose();
     return convertedImage;
 }
开发者ID:punker76,项目名称:Musick,代码行数:7,代码来源:ImageConvert.cs

示例2: getHead

        public ImageSource getHead(string UserName, string HeadImgUrl)
        {
            if (Data.heads.ContainsKey(UserName))
                return Data.heads[UserName];

            string url = "http://wx.qq.com" + HeadImgUrl;
            WebRequest request = WebRequest.Create(url);
            request.Headers.Add(HttpRequestHeader.Cookie, Data.cookie);
            WebResponse response = request.GetResponse();
            Trace.WriteLine("获取头像,长度:" + response.ContentLength);
            if (response.ContentLength == 0)
            {
                response.Close();
                return null;
            }
            Stream dataStream = response.GetResponseStream();
            System.Drawing.Image img = System.Drawing.Image.FromStream(dataStream);
            dataStream.Close();
            response.Close();

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
            IntPtr hBitmap = bmp.GetHbitmap();
            ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            Data.heads.Add(UserName, WpfBitmap);
            return WpfBitmap;
        }
开发者ID:xubo245,项目名称:WeChat,代码行数:27,代码来源:ImagePathConverter.cs

示例3: PngControl

        public PngControl(FileTabItem parent, OpenedFile fileDef)
        {
            InitializeComponent();
            m_parent = parent;
            m_openedFile = fileDef;
            m_openedFile.m_frame = this;

            string path = this.m_parent.m_filePath;

            if(System.IO.File.Exists(path))
            {
                m_Bitmap = DevIL.DevIL.LoadBitmap(path);
                try
                {
                    IntPtr ip = m_Bitmap.GetHbitmap();
                    m_imgSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                        ip, IntPtr.Zero, Int32Rect.Empty,
                        System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
                    MainWindow.DeleteObject(ip);

                    m_imgHeight = m_imgSource.PixelHeight;
                    m_imgWidth = m_imgSource.PixelWidth;
                    m_parent.itemFrame.Height = m_imgHeight;
                    m_parent.itemFrame.Width = m_imgWidth;
                    mx_image.Source = m_imgSource;
                    mx_image.Stretch = Stretch.Uniform;
                }
                catch
                {
                    Public.ResultLink.createResult("这不是一个合法的png文件(虽然后缀名是png)。");
                }
            }
        }
开发者ID:jaffrykee,项目名称:ui,代码行数:33,代码来源:PngControl.xaml.cs

示例4: LoadTabIcon

        public static object LoadTabIcon( string strFilename, string runtimeVersion )
        {
            string addinPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            System.Drawing.Bitmap appIcon = new System.Drawing.Bitmap(System.Drawing.Image.FromFile(addinPath+"\\"+strFilename));

            switch( runtimeVersion )
            {
                case "7.10":
                case "9.0":
                    return GetTransparentIPictureDispFromBitmapHandle( appIcon.GetHbitmap() );

                case "8.0":
                    return appIcon.GetHbitmap();

                default:
                    throw new ArgumentOutOfRangeException("runtimeVersion", string.Format(Constants.FrameworkNotSupported, runtimeVersion));
            }
        }
开发者ID:rameshnadarajan,项目名称:vutpp,代码行数:18,代码来源:ToolWindowUtil.cs

示例5: ConvertDrawingImageToWPFImage

 public System.Windows.Controls.Image ConvertDrawingImageToWPFImage(System.Drawing.Image gdiImg)
 {
     System.Windows.Controls.Image img = new System.Windows.Controls.Image();
     System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(gdiImg);
     IntPtr hBitmap = bmp.GetHbitmap();
     System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
     img.Source = WpfBitmap;
     return img;
 }
开发者ID:huylu,项目名称:brownuniversitylads,代码行数:9,代码来源:Helpers.cs

示例6: InitializeProfileOnGUI

 private void InitializeProfileOnGUI(Player profilePlayer)
 {
     if (File.Exists(@"GUI\Images\CustomVikings\" + profilePlayer.Name + ".png"))
     {
         System.Drawing.Image img = System.Drawing.Image.FromFile(@"GUI\Images\CustomVikings\" + profilePlayer.Name + ".png");
         System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
         BitmapSource bmpSrc = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),
             IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
         bmp.Dispose();
         VikingImage.Source = bmpSrc;
     }
 }
开发者ID:Bang-Bang-Studios,项目名称:Big-Sunday,代码行数:12,代码来源:MapWindow.xaml.cs

示例7: PanRight

		public PanRight()
		{
			string[] res = GetType().Assembly.GetManifestResourceNames();
			if(res.GetLength(0) > 0)
			{
				m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(GetType(), "PanRight.bmp"));
				if(m_bitmap != null)
				{
					m_bitmap.MakeTransparent(m_bitmap.GetPixel(1,1));
					m_hBitmap = m_bitmap.GetHbitmap();
				}
			}
			m_pHookHelper = new HookHelperClass ();
		}
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:14,代码来源:PanRight.cs

示例8: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            string query = "SELECT * FROM student";
            MySqlConnection myConnection = new MySqlConnection("server=localhost;user=root;password=root;database=xhz1;port=3306;");
            //MySqlCommand myCommand = new MySqlCommand(query, myConnection);
            //myConnection.Open();
            DataSet ds = MySqlHelper.ExecuteDataset(myConnection, query);
            //MySqlDataReader myDataReader = myCommand.ExecuteReader();

            //获取图片
            Image img = new Image();

            //新建一个student集合
            List<Student> StudentList = new List<Student>();
            foreach (DataTable dt in ds.Tables)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    byte[] by = (byte[])dr["image"];
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(by);
                    //System.IO.Stream ss =  System.IO.Stream;
                    //ms.CopyTo(ss);
                    System.Drawing.Image imgg = System.Drawing.Image.FromStream(ms,true);
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(imgg);
                    IntPtr hb = bmp.GetHbitmap();
                    System.Windows.Media.ImageSource wpfbitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hb, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    img.Source = wpfbitmap;
                    System.Windows.Media.ImageSource wpftooltip = wpfbitmap;
                    Student stu = new Student(dr["name"].ToString(), dr["number"].ToString(), wpfbitmap, wpftooltip);
                    StudentList.Add(stu);
                }
            }

            //新建一个student集合
            //List<Student> StudentList = null;
            //while (myDataReader.Read() == true)
            //{
            //    Student stu = new Student(myDataReader["name"].ToString(),myDataReader["number"].ToString());
            //    StudentList.Add(stu);
            //}
            //myDataReader.Close();
            myConnection.Close();

            this.student.ItemsSource = StudentList;
        }
开发者ID:haozhouxu,项目名称:Jewelry,代码行数:47,代码来源:MainWindow.xaml.cs

示例9: ConvertDrawingImageToWPFImage

        public static System.Windows.Controls.Image ConvertDrawingImageToWPFImage(System.Drawing.Image gdiImg)
        {
            System.Windows.Controls.Image img = new System.Windows.Controls.Image();

            //convert System.Drawing.Image to WPF image
            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(gdiImg))
            {
                IntPtr hBitmap = bmp.GetHbitmap();
                System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                img.Source = WpfBitmap;
                img.Width = 500;
                img.Height = 600;
                img.Stretch =  System.Windows.Media.Stretch.None;

                ScreenCapture.GDI32.DeleteObject(hBitmap);
            }
                return img;
        }
开发者ID:sczk,项目名称:collab-project,代码行数:19,代码来源:ImageConverter.cs

示例10: copyScreen

        public static BitmapSource copyScreen()
        {
            var left = 0;
            var top = 0;
            var right = 1920;
            var bottom = 1080;
            var width = right - left;
            var height = bottom - top;

            using (var screenBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                using (var bmpGraphics = System.Drawing.Graphics.FromImage(screenBmp))
                {
                    bmpGraphics.CopyFromScreen(left, top, 0, 0, new System.Drawing.Size(width, height));
                    return Imaging.CreateBitmapSourceFromHBitmap(
                            screenBmp.GetHbitmap(),
                            IntPtr.Zero,
                            Int32Rect.Empty,
                            BitmapSizeOptions.FromEmptyOptions());
                }
            }
        }
开发者ID:FUR10N,项目名称:Minesweeper,代码行数:22,代码来源:Win8Parser.cs

示例11: downloadAndSaveImage

        public void downloadAndSaveImage(string url, string filepath)
        {
            System.Drawing.Image drawingImage = null;
            System.Windows.Controls.Image wpfImage = new System.Windows.Controls.Image();
            try
            {
                System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
                httpWebRequest.AllowWriteStreamBuffering = true;
                httpWebRequest.Timeout = 20000;
                System.Net.WebResponse response = httpWebRequest.GetResponse();
                System.IO.Stream stream = response.GetResponseStream();
                drawingImage = System.Drawing.Image.FromStream(stream);

                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(drawingImage);
                IntPtr hBitmap = bmp.GetHbitmap();
                System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                wpfImage.Source = WpfBitmap;
                wpfImage.Width = 500;
                wpfImage.Height = 600;
                wpfImage.Stretch = System.Windows.Media.Stretch.Fill;
                bmp.Save(@filepath);
                stream.Close();
                response.Close();
                response.Close();
            }

            catch (Exception e)
            {
            }
        }
开发者ID:huylu,项目名称:brownuniversitylads,代码行数:31,代码来源:ArtworkModeWindow.xaml.cs

示例12: ConvertDrawingImageToWPFImage

        //void image_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        //{
        //    Image i = (Image)sender;
        //    lastMouseClick = e.GetPosition(i);
        //}
        //void image_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        //{
        //    if (e.RightButton == MouseButtonState.Pressed)
        //    {
        //        Image i = (Image)sender;
        //        Point mouseCurrentLocation = e.GetPosition(i);
        //        TranslateTransform translation = (TranslateTransform)((TransformGroup)((Image)sender).RenderTransform).Children[2];
        //        translation.X += mouseCurrentLocation.X - lastMouseClick.X;
        //        translation.Y += mouseCurrentLocation.Y - lastMouseClick.Y;
        //    }
        //}
        //void selectedVisual_MouseWheel(object sender, MouseWheelEventArgs e)
        //{
        //    if (e.LeftButton == MouseButtonState.Pressed &&
        //        ((ScaleTransform)((TransformGroup)((Image)sender).RenderTransform).Children[0]).ScaleX + e.Delta*0.001 > 0)
        //    {
        //        Image i = (Image)sender;
        //        Canvas c = (Canvas)i.Parent;
        //        ScaleTransform scale = (ScaleTransform)((TransformGroup)i.RenderTransform).Children[0];
        //        TranslateTransform translation = (TranslateTransform)((TransformGroup)i.RenderTransform).Children[2];
        //        translation.X += (i.Width * (scale.ScaleX + e.Delta * 0.001) - i.Width * scale.ScaleX) / 2;
        //        translation.Y += (i.Height * (scale.ScaleY + e.Delta * 0.001) - i.Height * scale.ScaleY) / 2;
        //        scale.ScaleX += e.Delta * 0.001;
        //        scale.ScaleY += e.Delta * 0.001;
        //        c.Height = i.Height * scale.ScaleY;
        //        c.Width = i.Width * scale.ScaleX;
        //    }
        //}
        /**********************************************************************************************************************************************/
        /**********************************************************************************************************************************************/
        /**********************************************************************************************************************************************/
        //method which purpose to convert Windows.Controls.Image to System.Drawing.Image so it could be converted to BitmapImage
        //and then used as a Source for ImageColorPicker to identify the color of pixel.
        System.Windows.Media.ImageSource ConvertDrawingImageToWPFImage()
        {
            System.Windows.Media.ImageSource WpfBitmap = null ;
            try
            {
                System.Windows.Controls.Image img = new System.Windows.Controls.Image();

                //convert System.Drawing.Image to WPF image
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(controlImageToDrawingImage());
                IntPtr hBitmap = bmp.GetHbitmap();
                WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            }
            catch { }

            return WpfBitmap;
        }
开发者ID:xtremas,项目名称:final-bachelor-project,代码行数:54,代码来源:MainWindow.xaml.cs

示例13: ShowFigure

        private void ShowFigure(Figure figure)
        {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ActualDocument.Pages[figure.PageIndex].FileName);

              BitmapSource source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
            System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
              CroppedImage = new CroppedBitmap(source, figure.FigureRect);

              contextMenu.Visibility = System.Windows.Visibility.Collapsed;
              figureViewer.Visibility = Visibility.Visible;
              isFigureViewerVisible = true;
        }
开发者ID:hcilab-um,项目名称:tPad,代码行数:12,代码来源:ActiveReaderApp.xaml.cs

示例14: GameWindow

        public GameWindow(GameOptions options)
        {
            InitializeComponent();
            CreateChildrenList();
            quotes = new Quotes();
            SoundManager.backgroundMusicPlayer.Open(new Uri("GUI/Sounds/Gameplay.mp3", UriKind.Relative));
            SoundManager.backgroundMusicPlayer.Play();
            gameOptions = options;
            switch (gameOptions._TypeOfGame)
            {
                case GameOptions.TypeOfGame.QuickMatch:
                    player1 = options._Player1;
                    player2 = options._Player2;
                    gameBrain = new GameBrain(player1);
                    Player1NameText.Text = player1.Name;
                    Player2NameText.Text = player2.Name;
                    isNetwork = false;
                    break;
                case GameOptions.TypeOfGame.Network:
                    player1 = options._Player1;
                    player2 = options._Player2;
                    gameBrain = new GameBrain(player1);
                    Player1NameText.Text = player1.Name;
                    Player2NameText.Text = player2.Name;
                    networkUtil = options._NetworkUtil;
                    networkUtil.MoveReceived += new moveReceivedHandler(NetworkMoveReceived);
                    isNetwork = true;
                    break;
                case GameOptions.TypeOfGame.AI:
                    player1 = options._Player1;
                    computerPlayer = options._ComputerPlayer;
                    gameBrain = new GameBrain(player1, computerPlayer);
                    Player1NameText.Text = player1.Name;
                    Player2NameText.Text = computerPlayer.Name;
                    if (!player1.ActivePlayer)
                        GetComputerMoveAsynchronously();
                    isNetwork = false;
                    break;
                default:
                    break;
            }
            ShowActivePlayer();
            if(File.Exists(@"GUI\Images\CustomVikings\" + player1.Name + ".png"))
            {
                System.Drawing.Image img = System.Drawing.Image.FromFile(@"GUI\Images\CustomVikings\" + player1.Name + ".png");
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
                BitmapSource bmpSrc = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),
                    IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                bmp.Dispose();
                VikingButton.Background = new ImageBrush(bmpSrc);
            }
            vikingArmPivot = new Point(167 + 40, this.Height - 420 + 121);
            zero = new Point(0, 0);
            topRight = new Point(Width, 0);
            iceGiantArmPivot = new Point(Width - 261, Height - 600);

            unMuteMusicVol = SoundManager.musicVolume / 16;
            unMuteSoundVol = SoundManager.sfxVolume / 16;
            currentMusicVol = SoundManager.musicVolume / 16;
            currentSoundVol = SoundManager.sfxVolume / 16;
            restoreMusicVol(currentMusicVol);
            restoreSoundVol(currentSoundVol);

            Stream cur = File.OpenRead("GUI/images/MouseArrow.cur");
            this.Cursor = new Cursor(cur);

            InitializeDragonOrigins();
            MakeDragonsVisble();
        }
开发者ID:Bang-Bang-Studios,项目名称:Integration,代码行数:69,代码来源:GameWindow.xaml.cs

示例15: ProcessSpriteSheet

        /// <summary>
        /// Laad de spritesheet image en snijd hem in losse sprites
        /// </summary>
        /// <param name="imageFile">Bestandsnaam van de spritesheet</param>
        /// <param name="xImages">Aantal horizontale images</param>
        /// <param name="yImages">Aantal verticale images</param>
        /// <param name="spriteWidth">Breedte van elke sprite</param>
        /// <param name="spriteHeight">Hoogte van elke sprite</param>
        /// <returns>Een array van sprites</returns>
        public BitmapSource[] ProcessSpriteSheet(string imageFile, int xImages, int yImages)
        {
            BitmapSource[] result = new BitmapSource[xImages * yImages];

            // Spritesheet inladen vanuit embedded resources
            System.Drawing.Bitmap src = new System.Drawing.Bitmap(_assembly.GetManifestResourceStream("DuckHunt.Resources.SpriteSheets." + imageFile));

            // Rechthoek aanmaken ter grootte van de sprites
            int spriteWidth = src.Width / xImages;
            int spriteHeight = src.Height / yImages;
            System.Drawing.Rectangle cropRect = new System.Drawing.Rectangle(0, 0, spriteWidth, spriteHeight);

            // Target bitmap voor losse sprites
            System.Drawing.Bitmap target;

            for (int col = 0; col < xImages; col++)
            {
                for (int row = 0; row < yImages; row++)
                {
                    // Zoek de positie van de huidige sprite
                    int currentX = col * spriteWidth;
                    int currentY = row * spriteHeight;
                    cropRect.X = currentX;
                    cropRect.Y = currentY;

                    // Maak een bitmap om de losse sprite op te tekenen
                    target = new System.Drawing.Bitmap(cropRect.Width, cropRect.Height);

                    // Snij de sprite uit
                    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(target))
                    {
                        g.DrawImage(src, new System.Drawing.Rectangle(0, 0, target.Width, target.Height), cropRect, System.Drawing.GraphicsUnit.Pixel);
                    }

                    // Zet de sprite om in een BitmapSource
                    BitmapSource frame = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(target.GetHbitmap(), IntPtr.Zero,
                    System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(target.Width, target.Height));

                    // Sla de sprite op in de array van sprites
                    int index = col + row * xImages;
                    result[index] = frame;
                }
            }

            return result;
        }
开发者ID:Chirimorin,项目名称:DuckHunt,代码行数:55,代码来源:SpriteSheetFactory.cs


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