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


C# BitmapImage.Clone方法代码示例

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


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

示例1: updateImage

        private void updateImage(object state)
        {
            byte[] buffer = new byte[10000000];

            while(IsAutoGrabbingMode)
            {
                int read, total = 0;
                HttpWebRequest req;
                try
                {
                    req = (HttpWebRequest)WebRequest.Create(Url);
                    // get response
                    WebResponse resp = req.GetResponse();

                    // get response stream
                    Stream stream = resp.GetResponseStream();

                    // read data from stream
                    while ((read = stream.Read(buffer, total, 1000)) != 0)
                    {
                        total += read;
                    }

                    byte[] btRezultBuffer = buffer.Take(total).ToArray();
                    //Console.WriteLine(total);
                    App.ViewModel.CurrentDisp.BeginInvoke((Action) (() =>
                    {
                        OnNewImage(btRezultBuffer);
                        if(bShowIpFrame)
                        {
                            MemoryStream ms = new MemoryStream(btRezultBuffer);
                            BitmapImage bmp = new BitmapImage();
                            bmp.BeginInit();
                            bmp.StreamSource = ms;
                            bmp.EndInit();
                            ImageFrame = bmp.Clone();
                        }
                    }));
                    
                }
                catch (UriFormatException ex)
                {
                    App.Log.Error("Ошибка при вводе URL IP-камеры", ex);
                    if(ErrorCounter++ > 5)
                    {
                        App.ViewModel.AddLogMessage("Ошибка при вводе URL IP-камеры. Опрос IP-камеры остановлен");
                        StopAutoGrabbing();
                    }
                    App.ViewModel.AddLogMessage("Ошибка при вводе URL IP-камеры. Повторный запрос...");

                }
                catch (WebException ex)
                {
                    App.Log.Error("Ошибка при вводе URL IP-камеры", ex);
                    if (ErrorCounter++ > 5)
                    {
                        App.ViewModel.AddLogMessage("Ошибка при вводе URL IP-камеры. Опрос IP-камеры остановлен");
                        StopAutoGrabbing();
                    }
                    App.ViewModel.AddLogMessage("Ошибка при вводе URL IP-камеры. Повторный запрос...");
                }
                catch (Exception ex)
                {
                    App.Log.Error("Неидентифицированная ошибка в UpdateImage", ex);
                    if (ErrorCounter++ > 5)
                    {
                        App.ViewModel.AddLogMessage("Неидентифицированная ошибка в UpdateImage. Опрос IP-камеры остановлен");
                        StopAutoGrabbing();
                    }
                    App.ViewModel.AddLogMessage("Неидентифицированная ошибка в UpdateImage. Повторный запрос...");
                }
                finally
                {
                    Thread.Sleep(AutoGrabbingTime);
                }
            }
           
            
        }
开发者ID:ericQiang,项目名称:selector-theater,代码行数:79,代码来源:IP_Camera.cs

示例2: WPFImageArray

 public WPFImageArray(BitmapImage Source, int ItemWidth, int ItemHeight)
 {
     m_CompleteImage = Source.Clone();
     m_CompleteImage.Freeze();
     Load(ItemWidth, ItemHeight);
 }
开发者ID:Shemetov,项目名称:OneScript,代码行数:6,代码来源:ImageArray.cs

示例3: InputButton_Click

        private void InputButton_Click(object sender, RoutedEventArgs e)
        {
            var openFile = new  System.Windows.Forms.OpenFileDialog();
            openFile.Filter = "image files|*.png;*jpg;*.jpeg;*.tif;*.tiff;;*.bmp;*.tga";
            openFile.Multiselect = true;
            openFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            if(openFile.ShowDialog()==System.Windows.Forms.DialogResult.OK)
            {
                ImageFIles =(string[]) openFile.FileNames.Clone();
                foreach(string singleImageFile in ImageFIles)
                {
                    BitmapImage thumbnail = new BitmapImage(new Uri(singleImageFile,UriKind.Absolute));

                    FileInfo tempFileInfo = new FileInfo(singleImageFile);
                    ImageItem singleImageItem = new ImageItem(thumbnail.Clone(), tempFileInfo.Name, tempFileInfo.DirectoryName,tempFileInfo.FullName, tempFileInfo.Extension);

                    ImageItemList.Add(singleImageItem);
                }
            }
            ImageListViewer.ItemsSource = ImageItemList;
            ImageListViewer.Items.Refresh();
        }
开发者ID:Neko3000,项目名称:waifu2x-handler,代码行数:22,代码来源:MainWindow.xaml.cs

示例4: buildImage

        private static System.Drawing.Bitmap buildImage(Tab tab, List<System.Drawing.Bitmap> images, System.Drawing.Bitmap finalImage, int offset, string key)
        {
            try
            {
                System.Drawing.Font font = new System.Drawing.Font(ApplicationState.FontCollection.Families[0], 11);
                int width = 0;
                int height = 0;
                int count = 0;
                float middleWidth = 0;
                foreach (Stream stream in ApplicationState.Model.GetImage(tab))
                {
                    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);

                    if (count == 1)
                    {
                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(200, 200)))
                        {
                            System.Drawing.SizeF measured = g.MeasureString(tab.Name, font);
                            width += (int)measured.Width;
                            middleWidth = measured.Width;
                        }
                    }
                    else
                    {
                        width += bitmap.Width;
                    }
                    height = bitmap.Height > height ? bitmap.Height : height;
                    images.Add(bitmap);
                    count++;
                }

                finalImage = new System.Drawing.Bitmap(width, height);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
                {
                    //set background color
                    g.Clear(System.Drawing.Color.Transparent);

                    //go through each image and draw it on the final image
                    int woffset = 0;
                    count = 0;
                    foreach (System.Drawing.Bitmap image in images)
                    {
                        int iwidth = image.Width;
                        if (count == 1)
                            iwidth = (int)middleWidth;
                        g.DrawImage(image, new System.Drawing.Rectangle(woffset, 0, iwidth, image.Height));
                        woffset += iwidth;
                        if (count == 1)
                            woffset -= 3; //The right image didn't align, similar to forums
                        count++;
                    }

                    g.DrawString(tab.Name, font, System.Drawing.Brushes.Yellow, images[0].Width - 2, 6); //Top
                    g.DrawString(tab.Name, font, System.Drawing.Brushes.Yellow, images[0].Width - 2, 32); //Mouse over version
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    finalImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                    stream.Position = 0;
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.StreamSource = stream;
                    bitmap.CacheOption = BitmapCacheOption.OnLoad;
                    bitmap.EndInit();

                    BitmapImage bitmapclone = (BitmapImage)bitmap.Clone();
                    bitmap = null;
                    imageCache.Add(key, new CroppedBitmap(bitmapclone, new Int32Rect(0, offset, (int)bitmapclone.Width, 26)));
                }
            }
            catch (Exception ex)
            {
                if (finalImage != null)
                    finalImage.Dispose();

                throw ex;
            }
            finally
            {
                foreach (System.Drawing.Bitmap image in images)
                    image.Dispose();
            }
            return finalImage;
        }
开发者ID:kakesu,项目名称:Procurement,代码行数:85,代码来源:StashHelper.cs

示例5: btnAddPhoto_Click

        private void btnAddPhoto_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.Title = "选择照片";
            openFileDialog.Filter = "jpg文件|*.jpg|bmp文件|*.bmp|gif文件|*.gif|png文件|*.png";
            openFileDialog.FileName = string.Empty;
            openFileDialog.FilterIndex = 1;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.DefaultExt = "jpg";

            System.Windows.Forms.DialogResult dr = openFileDialog.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    string filename = openFileDialog.FileName;
                    BitmapImage bi = new BitmapImage(new Uri(filename));
                    BitmapImage biBak = bi.Clone();
                    this.imgPhoto.Source = bi;
                    this.imgPhoto.Tag = biBak;
                }
                catch (Exception)
                {
                    return;
                }
            }
        }
开发者ID:wuqiangqiang,项目名称:dcs,代码行数:28,代码来源:SysPersonManager.xaml.cs


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