EndInit() public method

public EndInit ( ) : void
return void
Example #1
1
        public Model3DGroup Create(Color modelColor,string pictureName, Point3D startPos, double maxHigh)
        {
            try
            {
                Uri inpuri = new Uri(@pictureName, UriKind.Relative);
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = inpuri;
                bi.EndInit();
                ImageBrush imagebrush = new ImageBrush(bi);
                imagebrush.Opacity = 100;
                imagebrush.Freeze();

                Point[] ptexture0 = { new Point(0, 0), new Point(0, 1), new Point(1, 0) };
                Point[] ptexture1 = { new Point(1, 0), new Point(0, 1), new Point(1, 1) };

                SolidColorBrush modelbrush = new SolidColorBrush(modelColor);
                Model3DGroup cube = new Model3DGroup();
                Point3D uppercircle = startPos;
                modelbrush.Freeze();
                uppercircle.Y = startPos.Y + maxHigh;
                cube.Children.Add(CreateEllipse2D(modelbrush, uppercircle, _EllipseHigh, new Vector3D(0, 1, 0)));
                cube.Children.Add(CreateEllipse2D(modelbrush, startPos, _EllipseHigh, new Vector3D(0, -1, 0)));
                cube.Children.Add(CreateEllipse3D(imagebrush, startPos, _EllipseHigh, maxHigh, ptexture0));
                return cube;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
 public BitmapImage GetHeadIcon(string dir)
 {
     BitmapImage headBit = new BitmapImage();
     if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/" + dir + "/" + "logindata"))
     {
         headBit.BeginInit();
         string line1;
         string line2;
         string line3;
         using (StreamReader reader = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/" + dir + "/" + "logindata"))
         {
             line1 = reader.ReadLine();
             line2 = reader.ReadLine();
             line3 = reader.ReadLine();
         }
         headBit.UriSource = new Uri("https://minotar.net/avatar/" + line3);
         headBit.EndInit();
         return headBit;
     }
     else
     {
         headBit.BeginInit();
         headBit.UriSource = new Uri("https://minotar.net/avatar/char");
         headBit.EndInit();
         return headBit;
     }
 }
Example #3
0
        private void Play(object sender, RoutedEventArgs e)
        {
            BitmapImage logo = new BitmapImage();

            logo.BeginInit();
            if (MediaPlayer.Source != null)
            {
                if (!isPause)
                {
                    logo.UriSource = new Uri(@"Images\Play.png", UriKind.Relative);
                    logo.EndInit();
                    PlayButton.Source = logo;
                    MediaPlayer.Pause();
                    _timer.Stop();
                    isPause = true;
                }
                else
                {
                    logo.UriSource = new Uri(@"Images\Pause.png", UriKind.Relative);
                    logo.EndInit();
                    PlayButton.Source = logo;
                    MediaPlayer.Visibility = System.Windows.Visibility.Visible;
                    MediaPlayer.Play();
                    _timer.Start();
                    isPlaying = true;
                    isPause = false;
                }
            }
            else if (_LastVideoSource != null)
            {
                MediaPlayer.Source = _LastVideoSource;
                Play(sender, e);
            }
        }
        //-------------------------------------------------------------------------------------
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">ref NodeController</param>
        /// <param name="deviceType">type of device</param>
        public DeviceView(DeviceController device, DeviceType deviceType)
        {
            InitializeComponent();
            this.deviceController = device;

            BitmapImage bi3 = new BitmapImage();

            if (deviceType == DeviceType.dPc)
            {
                bi3.BeginInit();
                bi3.UriSource = new Uri("/GEditor;component/Resources/screen_zoom_in_ch.png", UriKind.Relative);
                bi3.EndInit();
            }
            else
            {
                if (deviceType == DeviceType.dSwitch)
                {
                    bi3.BeginInit();
                    bi3.UriSource = new Uri("/GEditor;component/Resources/switch_ch.png", UriKind.Relative);
                    bi3.EndInit();
                }
                else
                {
                    bi3.BeginInit();
                    bi3.UriSource = new Uri("/GEditor;component/Resources/password_ch.png", UriKind.Relative);
                    bi3.EndInit();
                }
            }
            this.point.Source = bi3;
            Canvas.SetZIndex(this, 2);
            this.point.Width = this.point.Height = radiusView;
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var imageParameter = value as string;
            if (imageParameter == null)
                imageParameter = parameter as string;

            if (!string.IsNullOrEmpty(imageParameter as string))
            {
                System.Drawing.Bitmap bitmap = null;
                var bitmapImage = new BitmapImage();

                // Application Resource - File Build Action is marked as None, but stored in Resources.resx
                // parameter= myresourceimagename
                try
                {
                    bitmap = Properties.Resources.ResourceManager.GetObject(imageParameter) as System.Drawing.Bitmap;
                }
                catch { }

                if (bitmap != null)
                {
                    using (var ms = new MemoryStream())
                    {
                        bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        bitmapImage.BeginInit();
                        bitmapImage.StreamSource = ms;
                        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                        bitmapImage.EndInit();
                    }
                    return bitmapImage;
                }

                // Embedded Resource - File Build Action is marked as Embedded Resource
                // parameter= MyWpfApplication.EmbeddedResource.myotherimage.png
                var asm = Assembly.GetExecutingAssembly();
                var stream = asm.GetManifestResourceStream(imageParameter);
                if (stream != null)
                {
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = stream;
                    bitmapImage.EndInit();
                    return bitmapImage;
                }

                // This is the standard way of using Image.SourceDependancyProperty.  You shouldn't need to use a converter to to this.
                //// Resource - File Build Action is marked as Resource
                //// parameter= pack://application:,,,/MyWpfApplication;component/Images/myfunkyimage.png
                //Uri imageUriSource = null;
                //if (Uri.TryCreate(imageParameter, UriKind.RelativeOrAbsolute, out imageUriSource))
                //{
                //    bitmapImage.BeginInit();
                //    bitmapImage.UriSource = imageUriSource;
                //    bitmapImage.EndInit();
                //    return bitmapImage;
                //}
            }
            return null;
        }
        private void ButtonEnter(object sender, EventArgs e)
        {
            BitmapImage logo = new BitmapImage();

            logo.BeginInit();
            if (sender == PlayButton)
            {
                if (isPause)
                    logo.UriSource = new Uri(@"Images\PlayOver.png", UriKind.Relative);
                else
                    logo.UriSource = new Uri(@"Images\PauseOver.png", UriKind.Relative);
                logo.EndInit();
                PlayButton.Source = logo;
            }
            if (sender == StopButton)
            {
                logo.UriSource = new Uri(@"Images\StopOver.png", UriKind.Relative);
                logo.EndInit();
                StopButton.Source = logo;
            }
            if (sender == VolumeButton)
            {
                if (MediaPlayer.Volume == 0)
                    logo.UriSource = new Uri(@"Images\SoundOffOver.png", UriKind.Relative);
                else
                    logo.UriSource = new Uri(@"Images\SoundOnOver.png", UriKind.Relative);
                logo.EndInit();
                VolumeButton.Source = logo;
            }
            if (sender == FullScreenButton)
            {
                if (this.WindowState == WindowState.Maximized)
                    logo.UriSource = new Uri(@"Images\LowScreenOver.png", UriKind.Relative);
                else
                    logo.UriSource = new Uri(@"Images\FullScreenOver.png", UriKind.Relative);
                logo.EndInit();
                FullScreenButton.Source = logo;
            }
            if (sender == ShowPannelButton)
            {
                if (!isPannelShow)
                    logo.UriSource = new Uri(@"Images\ShowPannelOver.png", UriKind.Relative);
                else
                    logo.UriSource = new Uri(@"Images\HidePannelOver.png", UriKind.Relative);
                logo.EndInit();
                ShowPannelButton.Source = logo;
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var rawImageData = value as byte[];

            if (rawImageData == null)
            {
#if DEBUG
                return(null);
#else
                Uri uri = new Uri("pack://application:,,,/Images/noimage.jpg");
                return(new BitmapImage(uri));
#endif
            }

            var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
            using (var stream = new MemoryStream(rawImageData))
            {
                bitmapImage.BeginInit();
                bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                bitmapImage.CacheOption   = BitmapCacheOption.OnLoad;
                bitmapImage.StreamSource  = stream;
                bitmapImage.EndInit();
            }
            return(bitmapImage);
        }
Example #8
0
        public BitmapImage ByteToBitmapImage(byte[] image)
        {
            byte[] myByte = image;
            if (image == null)
            {
                return(null);
            }
            BitmapImage newImage;

            using (MemoryStream ms = new MemoryStream(myByte))
            {
                var bmp = Bitmap.FromStream(ms);



                ms.Seek(0, System.IO.SeekOrigin.Begin);

                var bitmap = new System.Windows.Media.Imaging.BitmapImage();
                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = ms;
                bitmap.EndInit();
                newImage = bitmap;
            }

            return(newImage);
        }
        /// <summary>
        ///     Converts between a System.Drawing.Image and System.Windows.Media.Imaging.BitmapImage
        /// </summary>
        internal static SWMI.BitmapImage ToSystemWindowsMediaImagingBitmapImage(SD.Image fromImage)
        {
            if (fromImage == null)
            {
                return(null);
            }

            SWMI.BitmapImage       newImage = null;
            System.IO.MemoryStream stream   = new System.IO.MemoryStream();

            //Use the same output format that the Image is in, unless it is a MemoryBmp,
            //in which case use a regular Bmp.
            SDI.ImageFormat IntermediateFormat = fromImage.RawFormat;
            if (IntermediateFormat.Guid.CompareTo(SDI.ImageFormat.MemoryBmp.Guid) == 0)
            {
                IntermediateFormat = SDI.ImageFormat.Bmp;
            }

            fromImage.Save(stream, IntermediateFormat);
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            newImage = new SWMI.BitmapImage();
            newImage.BeginInit();
            newImage.StreamSource = stream;
            newImage.EndInit();

            return(newImage);
        }
Example #10
0
 public static System.Windows.Media.Imaging.BitmapImage ToImage(byte[] bytes)
 {
     //if (testCount++ > 10) { testCount = 0; throw new Exception("TestException"); }
     try
     {
         using (Stream ms = new System.IO.MemoryStream(bytes))
         {
             System.Windows.Media.Imaging.BitmapImage image = null;
             try
             {
                 System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                 {
                     try
                     {
                         image = new System.Windows.Media.Imaging.BitmapImage();
                         image.BeginInit();
                         image.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                         image.StreamSource = ms;
                         image.EndInit();
                         image.Freeze();
                     }
                     catch (Exception) { }
                 }));
             }
             catch (NullReferenceException) { }
             return(image);
         }
     }
     catch (Exception e) { }
     return(null);
 }
Example #11
0
        private Button FormButton(ProjectData data)
        {
            Button    button    = new Button();
            WrapPanel wrapPanel = new WrapPanel();
            Image     image     = new Image();
            TextBlock text      = new TextBlock();

            text.Text = System.IO.Path.GetFileName(data.FileName);
            System.Windows.Media.Imaging.BitmapImage bi3 = new System.Windows.Media.Imaging.BitmapImage();
            bi3.BeginInit();
            bi3.UriSource = new Uri("Resources/SmallIcon.ico", UriKind.Relative);
            bi3.EndInit();
            image.Stretch = System.Windows.Media.Stretch.Fill;
            image.Source  = bi3;
            image.Width   = 16;
            image.Height  = 16;
            image.Margin  = new System.Windows.Thickness(0, 0, 5, 0);

            wrapPanel.Orientation = Orientation.Horizontal;
            wrapPanel.Children.Add(image);
            wrapPanel.Children.Add(text);
            wrapPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            wrapPanel.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;

            button.HorizontalAlignment        = System.Windows.HorizontalAlignment.Stretch;
            button.VerticalAlignment          = System.Windows.VerticalAlignment.Stretch;
            button.VerticalContentAlignment   = System.Windows.VerticalAlignment.Stretch;
            button.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;

            button.Tag     = data;
            button.Content = wrapPanel;
            button.Click  += new System.Windows.RoutedEventHandler(button_Click);

            return(button);
        }
Example #12
0
        private void updateImage(ThumbnailInfo info)
        {
            updateOnlineStatus();
            System.Drawing.Image bmp = info.Thumbnail;

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);// 格式自处理,这里用 bitmap
                try
                {
                    WindowUtil.BeginInvoke(() =>
                    {
                        var bi = new System.Windows.Media.Imaging.BitmapImage();
                        bi.BeginInit();
                        bi.StreamSource = new MemoryStream(ms.ToArray()); // 不要直接使用 ms
                        bi.EndInit();
                        Thumbnail = bi;
                    });
                }
                catch
                {
                    Dispose();
                }
            }
        }
Example #13
0
        public BitmapImage LoadAnimationTexture(string fileName, bool transparent = false)
        {
            if (transparent)
            {
                FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                System.Drawing.Bitmap img = new System.Drawing.Bitmap(fileStream);
                fileStream.Close();
                var color = img.Palette.Entries[0];
                string hex = HexConverter(color);
                Instance.ViewModel.SpriteSheetTransparentColors.Add((Color)ColorConverter.ConvertFromString(hex));
                img.MakeTransparent(color);
                return (BitmapImage)BitmapConversion.ToWpfBitmap(img);
            }
            else
            {
                FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

                var img = new System.Windows.Media.Imaging.BitmapImage();
                img.BeginInit();
                img.StreamSource = fileStream;
                img.EndInit();
                return img;
            }

        }
Example #14
0
        public static Media.Brush GetThumbnailBrush(string fileName, int width = 256, int height = 256, ThumbnailOptions options = ThumbnailOptions.None)
        {
            IntPtr hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);

            try
            {
                Bitmap bmp = Bitmap.FromHbitmap(hBitmap);
                Media.Imaging.BitmapImage img = new Media.Imaging.BitmapImage();
                using (var ms = new MemoryStream())
                {
                    bmp.Save(ms, ImageFormat.Png);
                    img.BeginInit();
                    img.StreamSource = ms;
                    img.CacheOption  = Media.Imaging.BitmapCacheOption.OnLoad;
                    img.EndInit();
                    img.Freeze();
                }
                return(new Media.ImageBrush(img));
            }
            finally
            {
                // delete HBitmap to avoid memory leaks
                DeleteObject(hBitmap);
            }
        }
Example #15
0
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            // empty images are empty...
            if (value == null)
            {
                return(null);
            }

            var image = (System.Drawing.Image)value;
            // Winforms Image we want to get the WPF Image from...
            var bitmap = new System.Windows.Media.Imaging.BitmapImage();

            bitmap.BeginInit();
            bitmap.CacheOption = BitmapCacheOption.OnLoad;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                // Save to a memory stream...
                image.Save(memoryStream, ImageFormat.Bmp);
                // Rewind the stream...
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap.StreamSource = memoryStream;
                bitmap.EndInit();
            }
            return(bitmap);
        }
Example #16
0
        /// <summary>
        /// 将图片文件转换成BitmapSource
        /// </summary>
        /// <param name="sFilePath"></param>
        /// <returns></returns>
        public static System.Windows.Media.Imaging.BitmapSource ToBitmapSource(string sFilePath)
        {
            try
            {
                using (System.IO.FileStream fs = new System.IO.FileStream(sFilePath,
                                                                          System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    fs.Close();
                    fs.Dispose();

                    System.Windows.Media.Imaging.BitmapImage bitmapImage =
                        new System.Windows.Media.Imaging.BitmapImage();
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer))
                    {
                        bitmapImage.BeginInit();
                        bitmapImage.StreamSource = ms;
                        bitmapImage.CacheOption  = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                        bitmapImage.EndInit();
                        bitmapImage.Freeze();
                    }
                    return(bitmapImage);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #17
0
        public static System.Windows.Media.Imaging.BitmapImage ByteArrayToBitmapImage(byte[] imageData)
        {
            System.Windows.Media.Imaging.BitmapImage image = null;

            // если нет изображения, то вернуть из файла
            if (imageData == null || imageData.Length == 0)
            {
                string filePath = ImageHelper.GetFileNameBy(@"AppImages\no_image.png");
                if (System.IO.File.Exists(filePath) == true)
                {
                    image = new System.Windows.Media.Imaging.BitmapImage(new Uri(filePath, UriKind.Absolute));
                }
            }
            else
            {
                image = new System.Windows.Media.Imaging.BitmapImage();
                using (var stream = new MemoryStream(imageData))
                {
                    stream.Seek(0, SeekOrigin.Begin);

                    image.BeginInit();
                    image.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.PreservePixelFormat;
                    image.CacheOption   = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                    image.UriSource     = null;
                    image.StreamSource  = stream;
                    image.EndInit();
                }
            }

            image.Freeze();
            return(image);
        }
Example #18
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var rawImageData = value as byte[];

            if (rawImageData == null)
            {
                return(null);
            }

            var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();

            using (MemoryStream strm = new MemoryStream())
            {
                strm.Write(rawImageData, 0, rawImageData.Length);
                strm.Position = 0;
                System.Drawing.Image img = System.Drawing.Image.FromStream(strm);

                bitmapImage.BeginInit();
                MemoryStream ms = new MemoryStream();
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

                ms.Seek(0, SeekOrigin.Begin);
                bitmapImage.StreamSource = ms;
                bitmapImage.EndInit();
            }
            return(bitmapImage);
        }
Example #19
0
 public void loadImage(int id)
 {
     try
     {
         string select = "select * from Images where ImageId='" + id + "'";
         DataTable dt = SiaWin.Func.SqlDT(select, "Imagen", 0);
         if (dt.Rows.Count > 0)
         {
             byte[] blob = (byte[])dt.Rows[0]["Image"];
             MemoryStream stream = new MemoryStream();
             stream.Write(blob, 0, blob.Length);
             stream.Position = 0;
             System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
             System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
             bi.BeginInit();
             MemoryStream ms = new MemoryStream();
             img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
             ms.Seek(0, SeekOrigin.Begin);
             bi.StreamSource = ms;
             bi.EndInit();
             this.Icon = bi;
         }
     }
     catch (Exception w)
     {
         SiaWin.Func.SiaExeptionGobal(w);
         MessageBox.Show("error en el loadImage:" + w);
     }
 }
Example #20
0
        public static System.Windows.Media.Imaging.BitmapImage DrawingImageToBitmapImage(System.Drawing.Image dImage)
        {
            if (dImage == null)
            {
                return(null);
            }

            var image = new System.Windows.Media.Imaging.BitmapImage();

            using (var stream = new MemoryStream())
            {
                dImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);

                stream.Seek(0, SeekOrigin.Begin);

                image.BeginInit();
                image.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.PreservePixelFormat;
                image.CacheOption   = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                image.UriSource     = null;
                image.StreamSource  = stream;
                image.EndInit();
            }

            image.Freeze();
            return(image);
        }
        public AnimatedGifWindow()
        {
            var img = new Image();
            var src = default(BitmapImage);

            var source = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "background.gif");

            if (File.Exists(source)) {
                src = new BitmapImage();
                src.BeginInit();
                src.StreamSource = File.OpenRead(source);
                src.EndInit();
            
                ImageBehavior.SetAnimatedSource(img, src);
                this.Content = img;
                this.Width = src.Width;
                this.Height = src.Height;
            }
                        
            this.AllowsTransparency = true;
            this.WindowStyle = WindowStyle.None;
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            this.ShowInTaskbar = true;
            this.Topmost = true;
            this.TaskbarItemInfo = new TaskbarItemInfo {
                ProgressState = TaskbarItemProgressState.Normal
            };
            this.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
        }
Example #22
0
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (value == null)
                {
                    return(null);
                }

                //Your incoming ToolImage object
                var image = (System.Drawing.Image)value;

                //new-up a BitmapImage
                var bitmap = new System.Windows.Media.Imaging.BitmapImage();

                bitmap.BeginInit();

                //stream image info from Image to BitmapImage
                MemoryStream memoryStream = new MemoryStream();

                image.Save(memoryStream, ImageFormat.Bmp);
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap.StreamSource = memoryStream;
                bitmap.EndInit();

                //return the BitmapImage that you can bind to the XAML
                return(bitmap);
            }
Example #23
0
        public BitmapImage GetMenuItemImage(string imageID, string companyID)
        {
            System.Windows.Media.Imaging.BitmapImage wpfImg = new System.Windows.Media.Imaging.BitmapImage();
            try
            {
                DBStoredImage dbStoredImage = _context.DBStoredImages.First();
                _context.IgnoreResourceNotFoundException = true;
                _context.MergeOption = MergeOption.NoTracking;
                dbStoredImage        = (from q in _context.DBStoredImages
                                        where q.ImageID == imageID &&
                                        q.CompanyID == companyID
                                        select q).FirstOrDefault();

                MemoryStream stream = new MemoryStream();
                stream.Write(dbStoredImage.StoredImage, 0, dbStoredImage.StoredImage.Length);

                //System.Windows.Media.Imaging.BitmapImage wpfImg = new System.Windows.Media.Imaging.BitmapImage();
                wpfImg.BeginInit();
                wpfImg.StreamSource = stream;
                wpfImg.EndInit();
            }//if image fails we will return the empty bitmapimage object
            catch
            {//reset it as to have a new crisp empty one to return... as to hopefull not cause errors when trying to display a corrupted one...
                wpfImg = new System.Windows.Media.Imaging.BitmapImage();
            }
            return(wpfImg);
        }
Example #24
0
        //public static BitmapImage MemberImage(BitmapImage Member)
        //{
        //    get
        //    {
        //        var image = new BitmapImage();

        //        if (Member != null)
        //        {
        //            WebRequest request = WebRequest.Create(new Uri(Member. .ImageFilePath, UriKind.Absolute));
        //            request.Timeout = -1;
        //            WebResponse response = request.GetResponse();
        //            Stream responseStream = response.GetResponseStream();
        //            BinaryReader reader = new BinaryReader(responseStream);
        //            MemoryStream memoryStream = new MemoryStream();

        //            byte[] bytebuffer = new byte[BytesToRead];
        //            int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);

        //            while (bytesRead > 0)
        //            {
        //                memoryStream.Write(bytebuffer, 0, bytesRead);
        //                bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
        //            }

        //            image.BeginInit();
        //            memoryStream.Seek(0, SeekOrigin.Begin);

        //            image.StreamSource = memoryStream;
        //            image.EndInit();
        //        }

        //        return image;
        //    }
        //}
        #endregion

        public static BitmapImage Image_http_Loaded(Uri _uri) // (string _str)
        {
            var BitmapImageTemp = new System.Windows.Media.Imaging.BitmapImage();
            int BytesToRead     = 100;

            WebRequest request = WebRequest.Create(_uri); // (new Uri(_str, UriKind.Absolute))

            request.Timeout = -1;
            WebResponse  response       = request.GetResponse();
            Stream       responseStream = response.GetResponseStream();
            BinaryReader reader         = new BinaryReader(responseStream);
            MemoryStream memoryStream   = new MemoryStream();

            byte[] bytebuffer = new byte[BytesToRead];
            int    bytesRead  = reader.Read(bytebuffer, 0, BytesToRead);

            while (bytesRead > 0)
            {
                memoryStream.Write(bytebuffer, 0, bytesRead);
                bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
            }

            BitmapImageTemp.BeginInit();
            memoryStream.Seek(0, SeekOrigin.Begin);

            BitmapImageTemp.StreamSource = memoryStream;
            BitmapImageTemp.EndInit();

            return(BitmapImageTemp);
        }
Example #25
0
        public static BitmapImage ToBitmapImage(this byte[] bytes)
        {
            var imageSource = new BitmapImage();
            try
            {
                if (bytes == null || bytes.Length == 0)
                {
                    return imageSource;
                }

                using (var stream = new MemoryStream(bytes))
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    imageSource.BeginInit();
                    imageSource.StreamSource = stream;
                    imageSource.CacheOption = BitmapCacheOption.OnLoad;
                    imageSource.EndInit();
                }
            }
            catch (Exception)
            {
                //Log
            }

            return imageSource;
        }
Example #26
0
        /// <summary>
        /// Gets the BitmapImage of the specified push pin.
        /// </summary>
        /// <param name="pinId">Pushpin id</param>
        /// <returns>BitmapImage of the specified push pin</returns>
        internal static BitmapImage GetPushPinBitmapImage(int pinId)
        {
            BitmapImage bitmapImage = null;

            if (pinBitmapImageCache.ContainsKey(pinId))
            {
                bitmapImage = pinBitmapImageCache[pinId];
            }
            else
            {
                using (System.Drawing.Bitmap bitmap = PushPin.GetPushPinBitmap(pinId))
                {
                    using (MemoryStream bitmapStream = new MemoryStream())
                    {
                        bitmap.Save(bitmapStream, System.Drawing.Imaging.ImageFormat.Png);
                        bitmapImage = new System.Windows.Media.Imaging.BitmapImage();

                        bitmapImage.BeginInit();
                        bitmapImage.StreamSource  = new MemoryStream(bitmapStream.ToArray());
                        bitmapImage.CreateOptions = BitmapCreateOptions.None;
                        bitmapImage.CacheOption   = BitmapCacheOption.Default;
                        bitmapImage.EndInit();

                        pinBitmapImageCache.Add(pinId, bitmapImage);
                    }
                }
            }

            return(bitmapImage);
        }
Example #27
0
        private void LiveControlManager_OnScreenshotReceived(object sender, ScreenshotMessageEventArgs e)
        {
            var screenshot = e.Screenshot;

            using (var stream = new System.IO.MemoryStream(screenshot.Image))
            {
                Image image  = Image.FromStream(stream);
                var   bitmap = new System.Windows.Media.Imaging.BitmapImage();
                bitmap.BeginInit();
                MemoryStream memoryStream = new MemoryStream();
                // Save to a memory stream...
                image.Save(memoryStream, ImageFormat.Bmp);
                // Rewind the stream...
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap.StreamSource = memoryStream;
                bitmap.EndInit();

                //this.BGImage.Source = bitmap;

                //if (dispatcher != null)
                //Dispatcher.BeginInvoke(MainWindow.RefreshUI,bitmap);
                //if (ShowRegionOutlines)
                //{
                //    var gfx = gdiScreen1.CreateGraphics();
                //    gfx.DrawLine(pen, new Point(e.Screenshot.Region.X, e.Screenshot.Region.Y), new Point(e.Screenshot.Region.X + e.Screenshot.Region.Width, e.Screenshot.Region.Y));
                //    gfx.DrawLine(pen, new Point(e.Screenshot.Region.X + e.Screenshot.Region.Width, e.Screenshot.Region.Y), new Point(e.Screenshot.Region.X + e.Screenshot.Region.Width, e.Screenshot.Region.Y + e.Screenshot.Region.Y));
                //    gfx.DrawLine(pen, new Point(e.Screenshot.Region.X + e.Screenshot.Region.Width, e.Screenshot.Region.Y + e.Screenshot.Region.Y), new Point(e.Screenshot.Region.X, e.Screenshot.Region.Y + e.Screenshot.Region.Y));
                //    gfx.DrawLine(pen, new Point(e.Screenshot.Region.X, e.Screenshot.Region.Y + e.Screenshot.Region.Y), new Point(e.Screenshot.Region.X, e.Screenshot.Region.Y));
                //    gfx.Dispose();
                //}
                //gdiScreen1.Draw(image, screenshot.Region);
            }

            // LiveControlManager.RequestScreenshot();
        }
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			if (value == null)
				return null;
			if (value.ToString().IsEmpty() || (value.ToString() == "none")) {
				var image = new BitmapImage();
				image.BeginInit();
				image.UriSource = new Uri("pack://application:,,,/PCSX2Bonus;component/Images/noart.png", UriKind.Absolute);
				image.DecodePixelWidth = 0x109;
				image.DecodePixelHeight = 350;
				image.EndInit();
				if (image.CanFreeze)
					image.Freeze();
				return image;
			}
			var image2 = new BitmapImage();
			using (var stream = File.OpenRead(value.ToString())) {
				image2.BeginInit();
				image2.StreamSource = stream;
				image2.DecodePixelWidth = 0x109;
				image2.DecodePixelHeight = 350;
				image2.CacheOption = BitmapCacheOption.OnLoad;
				image2.EndInit();
			}
			if (image2.CanFreeze)
				image2.Freeze();
			return image2;
		}
Example #29
0
        /// <summary>
        /// Gets a bitmap inside the given assembly at the given path therein.
        /// </summary>
        /// <param name="uri">
        /// The relative URI.
        /// </param>
        /// <param name="assemblyName">
        /// Name of the assembly.
        /// </param>
        /// <returns>
        /// </returns>
        public static BitmapImage GetBitmap(Uri uri, string assemblyName)
        {
            if (uri == null)
            {
                return null;
            }

            var stream = GetStream(uri, assemblyName);

            if (stream == null)
            {
                return null;
            }

            using (stream)
            {
                var bmp = new BitmapImage();

                bmp.BeginInit();
                bmp.StreamSource = stream;
                bmp.EndInit();

                return bmp;
            }
        }
      public async Task<ImageSource> DownloadPicture(string imageUri)
      {
         var request = (HttpWebRequest)WebRequest.Create(imageUri);
         if (string.IsNullOrEmpty(Configuration.SessionCookies) == false)
         {
            request.CookieContainer = new CookieContainer();
            request.CookieContainer.SetCookies(request.RequestUri, Configuration.SessionCookies);
         }

         var response = (HttpWebResponse)(await request.GetResponseAsync());

         using (Stream inputStream = response.GetResponseStream())
         using (Stream outputStream = new MemoryStream())
         {
            var buffer = new byte[4096];
            int bytesRead;
            do
            {
               bytesRead = await inputStream.ReadAsync(buffer, 0, buffer.Length);
               outputStream.Write(buffer, 0, bytesRead);
            } while (bytesRead != 0);

            var bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapImage.StreamSource = outputStream;
            bitmapImage.EndInit();
            bitmapImage.Freeze();

            return bitmapImage;
         }
      }
        /// <summary>
        /// Gets the bitmap image.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>BitmapImage.</returns>
        /// <exception cref="System.ArgumentNullException">uri</exception>
        public BitmapImage GetBitmapImage(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            var bitmap = new BitmapImage
            {
                CreateOptions = BitmapCreateOptions.DelayCreation,
                CacheOption = BitmapCacheOption.OnDemand,
                UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable)
            };

            var scalingMode = _config.Configuration.EnableHighQualityImageScaling
                                  ? BitmapScalingMode.Fant
                                  : BitmapScalingMode.LowQuality;

            RenderOptions.SetBitmapScalingMode(bitmap, scalingMode);

            bitmap.BeginInit();
            bitmap.UriSource = uri;
            bitmap.EndInit();

            return bitmap;
        }
Example #32
0
        public ExtTreeNode(Image icon, string title)
            : this()
        {
            if (icon != null)
            {
                this.icon = icon;
            }
            else//test inti icon
            {
                this.icon = new Image();
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.UriSource = new Uri(@"pack://*****:*****@"../../icons/add.png", UriKind.RelativeOrAbsolute);
                bitmapImage.EndInit();
                this.icon.Source = bitmapImage;
            }

            this.icon.Width = 16;
            this.icon.Height = 16;

            this.title = title;

            TextBlock tb = new TextBlock();
            tb.Text = title;
            Grid grid = new Grid();
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.Children.Add(this.icon);
            grid.Children.Add(tb);
            Grid.SetColumn(this.icon, 0);
            Grid.SetColumn(tb, 1);
            this.Header = grid;
        }
        //TODO filter by mimetype
        public void ShowImage(MemoryStream stream)
        {
            try
            {
                stream.Position = 0;
                var bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = stream;
                bitmapImage.EndInit();

                image1.Width = bitmapImage.Width;
                image1.Height = bitmapImage.Height;

                var screenInfo = GetScreenInfo();

                image1.Height = screenInfo.Height - 150;
                image1.Width = (image1.Height * bitmapImage.Width) / bitmapImage.Height;

                Height = image1.Height + 3;
                Width = image1.Width + 3;

                image1.Source = bitmapImage;
            }
            catch (NotSupportedException)
            { }
        }
Example #34
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void init(string[] func_list)
        {
            for (int i = 0; i < func_list.Length; i++)
            {
                // 分割线
                Image img = new Image();
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(AppConfig.IconPath, UriKind.Relative);
                bi.EndInit();
                img.Margin = new Thickness(5, (i + 1) * 72 - 20, 0, 0);
                img.Width = 150;
                img.Height = 10;
                img.HorizontalAlignment = HorizontalAlignment.Left;
                img.VerticalAlignment = VerticalAlignment.Top;
                img.Source = bi;

                // 按钮
                MainNavButton mnb = new MainNavButton();
                mnb.Tag = func_list[i];
                mnb.id = i;
                mnb.init();
                mnb.HorizontalAlignment = HorizontalAlignment.Left;
                mnb.VerticalAlignment = VerticalAlignment.Top;
                mnb.Margin = new Thickness(0, (i + 1) * 72 - 20 + 3, 0, 0);
                if (i == 0)
                {
                    mnb.change_state();
                }
                mnbs.Add(mnb);
                this.main.Children.Add(img);
                this.main.Children.Add(mnb);
            }

        }
		public override bool View(DecompilerTextView textView)
		{
			try {
				AvalonEditTextOutput output = new AvalonEditTextOutput();
				Data.Position = 0;
				BitmapImage image = new BitmapImage();

				//HACK: windows imaging does not understand that .cur files have the same layout as .ico
				// so load to data, and modify the ResourceType in the header to make look like an icon...
				byte[] curData = ((MemoryStream)Data).ToArray();
				curData[2] = 1;
				using (Stream stream = new MemoryStream(curData)) {
					image.BeginInit();
					image.StreamSource = stream;
					image.EndInit();
				}

				output.AddUIElement(() => new Image { Source = image });
				output.WriteLine();
				output.AddButton(Images.Save, "Save", delegate {
					Save(null);
				});
				textView.ShowNode(output, this, null);
				return true;
			}
			catch (Exception) {
				return false;
			}
		}
Example #36
0
        public FileListItem(string captionText, string imagePath)
            : base()
        {
            Margin = new Thickness(13);

            var panel = new StackPanel();
            var imageSource = new BitmapImage();
            var image = new Image();
            var caption = new TextBlock();

            imageSource.BeginInit();
            imageSource.UriSource = new Uri(imagePath, UriKind.Relative);
            imageSource.EndInit();

            image.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            image.Source = imageSource;
            image.Height = 64;
            image.Width = 64;
            image.ToolTip = "Select & click on 'Table' for data view.";

            caption.TextAlignment = TextAlignment.Center;
            caption.TextWrapping = TextWrapping.Wrap;
            caption.Text = captionText;

            Caption = captionText;

            if (caption.Text.Length <= 18)
                caption.Text += "\n ";

            panel.Children.Add(image);
            panel.Children.Add(caption);

            Child = panel;
        }
        static TopWallpaperRenderer()
        {
            ScreenArea = new Rect(0, 0, 412, 240);

            var defTopAlt = new BitmapImage();
            defTopAlt.BeginInit();
            //defTopAlt.StreamSource = (Stream) Extensions.GetResources(@"TopAlt_DefMask\.png").First().Value;
            defTopAlt.UriSource = new Uri(@"pack://application:,,,/ThemeEditor.WPF;component/Resources/TopAlt_DefMask.png");
            defTopAlt.CacheOption = BitmapCacheOption.OnLoad;
            defTopAlt.EndInit();

            var bgrData = defTopAlt.GetBgr24Data();
            RawTexture rTex = new RawTexture(defTopAlt.PixelWidth, defTopAlt.PixelHeight, RawTexture.DataFormat.A8);
            rTex.Encode(bgrData);
            DefaultTopSquares = new TextureViewModel(rTex, null);

            RenderToolFactory.RegisterTool<PenTool, Pen>
                (key => new Pen(new SolidColorBrush(key.Color)
                {
                    Opacity = key.Opacity
                },
                            key.Width));

            RenderToolFactory.RegisterTool<SolidColorBrushTool, Brush>
                (key => new SolidColorBrush(key.Color)
                {
                    Opacity = key.Opacity
                });

            RenderToolFactory.RegisterTool<LinearGradientBrushTool, Brush>
                (key => new LinearGradientBrush(key.ColorA, key.ColorB, key.Angle)
                {
                    Opacity = key.Opacity
                });

            RenderToolFactory.RegisterTool<ImageBrushTool, Brush>
                (key => new ImageBrush(key.Image)
                {
                    TileMode = key.Mode,
                    ViewportUnits = key.ViewportUnits,
                    Viewport = key.Viewport,
                    Opacity = key.Opacity
                });

            Type ownerType = typeof(TopWallpaperRenderer);
            IsEnabledProperty
                .OverrideMetadata(ownerType, new FrameworkPropertyMetadata(false, OnIsEnabledChanged));

            ClipToBoundsProperty.OverrideMetadata(ownerType,
                new FrameworkPropertyMetadata(true, null, (o, value) => true));
            WidthProperty.OverrideMetadata(ownerType,
                new FrameworkPropertyMetadata(412.0, null, (o, value) => 412.0));
            HeightProperty.OverrideMetadata(ownerType,
                new FrameworkPropertyMetadata(240.0, null, (o, value) => 240.0));

            EffectProperty.OverrideMetadata(ownerType,
                new FrameworkPropertyMetadata(default(WarpEffect),
                    null,
                    (o, value) => ((TopWallpaperRenderer) o).GetWarpEffectInstance()));
        }
        public static BitmapImage ComposerToThumbnail(Composer composer)
        {
            var thumbnail = (BitmapImage)null;

            if (_thumbnailCache.TryGetValue(composer.ComposerId, out thumbnail))
            {
                return _thumbnailCache[composer.ComposerId];
            }

            var directoryPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create)}\Music Timeline\Resources\Thumbnails\";

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            var thumbnailPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create)}\Music Timeline\Resources\Thumbnails\{composer.ComposerId}.jpg";
            var thumbnailUri = new Uri(thumbnailPath, UriKind.Absolute);

            if (File.Exists(thumbnailPath))
            {
                thumbnail = new BitmapImage();
                thumbnail.BeginInit();
                thumbnail.DecodePixelHeight = 50;
                thumbnail.StreamSource = new MemoryStream(File.ReadAllBytes(thumbnailPath));
                thumbnail.EndInit();
                thumbnail.Freeze();

                _thumbnailCache[composer.ComposerId] = thumbnail;

                return thumbnail;
            }

            return CreateThumbnail(composer);
        }
Example #39
0
        public MainWindow()
        {
            InitializeComponent();
            Window w = new DBItems();
            VkRepository.ImageReady += () =>
            {
                UserAvatar.Children.Clear();

                Image i = new Image();
                BitmapImage src = new BitmapImage();
                src.BeginInit();
                src.UriSource = new Uri(string.Format("{0}avatar.jpg", VkRepository.counter.ToString()), UriKind.Relative);
                src.CacheOption = BitmapCacheOption.OnLoad;
                src.EndInit();
                i.Source = src;
                i.Stretch = Stretch.Uniform;
                UserAvatar.Children.Add(i);
            };
            AuthWindow.OnLoggedIn += (c) =>
                {
                    AuthInfo.Text = VkRepository.GetUserInfo(c).ToString();
                };
            VkRepository.UserDbLoaded += (users) =>
            {
                w.Show();
            };
        }
Example #40
0
        public System.Windows.Media.Imaging.BitmapImage createImage()
        {
            string fileName = filePath;

            using (var file = new org.pdfclown.files.File(fileName)) {
                Document document = file.Document;
                Pages    pages    = document.Pages;

                Page                 page      = pages[0];
                SizeF                imageSize = page.Size;
                Renderer             renderer  = new Renderer();
                System.Drawing.Image image     = renderer.Render(page, imageSize);

                // Winforms Image we want to get the WPF Image from
                var bitmap = new System.Windows.Media.Imaging.BitmapImage();
                bitmap.BeginInit();
                MemoryStream memoryStream = new MemoryStream();
                // Save to a memory stream
                image.Save(memoryStream, ImageFormat.Bmp);
                // Rewind the stream
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap.StreamSource = memoryStream;
                bitmap.EndInit();

                return(bitmap);
            }
        }
		static ImageSource CreateImageSource2(byte[] data) {
			var bimg = new BitmapImage();
			bimg.BeginInit();
			bimg.StreamSource = new MemoryStream(data);
			bimg.EndInit();
			return bimg;
		}
        public BitmapImage getPacImage()
        {
            // double width = (Image_Grid.ActualWidth * 160 )/ 700;
            // double height = (Image_Grid.ActualHeight * 160 )/ 190;

            RenderTargetBitmap rtb = new RenderTargetBitmap((int)Image_Grid.ActualWidth, (int)Image_Grid.ActualHeight, 96, 96, PixelFormats.Pbgra32);

            rtb.Render(Image_Grid);
            PngBitmapEncoder png = new PngBitmapEncoder();

            png.Frames.Add(BitmapFrame.Create(rtb));
            MemoryStream stream = new MemoryStream();

            png.Save(stream);
            System.Drawing.Image bmp = System.Drawing.Image.FromStream(stream);

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);// 格式自处理,这里用 bitmap
            // 下行,初始一个 ImageSource 作为 myImage 的Source
            System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
            bi.BeginInit();
            bi.StreamSource = new MemoryStream(ms.ToArray()); // 不要直接使用 ms
            bi.EndInit();
            //myImage.Source = bi; // done!
            ms.Close();

            return(bi);
        }
Example #43
0
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
   string path = value as string;
   if (path != null)
   {
     BitmapImage image = new BitmapImage();
     using (FileStream stream = File.OpenRead(path))
     {
       try
       {
         image.BeginInit();
         image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
         image.StreamSource = stream;
         image.CacheOption = BitmapCacheOption.OnLoad;
         image.EndInit(); // load the image from the stream
       }
       catch (NotSupportedException)
       {
         return null;
       }
       catch (FileFormatException)
       {
         return null;
       }
     } // close the stream
     return image;
   }
   return null;
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var bytes = value as byte[];

            if (bytes == null || bytes.Length == 0)
                return DependencyProperty.UnsetValue;

            var image = new BitmapImage();

            using (Stream stream = new MemoryStream(bytes))
            {
                image.BeginInit();
                image.StreamSource = stream;
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.EndInit();
            }

            if (!image.IsFrozen)
            {
                image.AddMemoryPressure();
                image.Freeze();
            }

            return image;
        }
Example #45
0
        private void busquedaBtn_Click(object sender, RoutedEventArgs e)
        {
            Client cliente = ControllerCliente.Instance.buscarCliente(busquedaBox.Text);
            if (cliente == null)
            {
                MessageBox.Show("No existe con ese carnet");
            }
            else
            {
                ciBox.Text = cliente.ci.ToString();
                nombreBox.Text = cliente.nombre;
                PaternoBox.Text = cliente.apellidoPaterno;
                MaternoBox.Text = cliente.apellidoMaterno;
                DomicilioBox.Text = cliente.domicilio;
                ZonaBox.Text = cliente.zona;
                emailBox.Text = cliente.email;
                telefonoCasaBox.Text = cliente.telefonoCasa;
                telefonoOficinaBox.Text = cliente.telefonoOficina;
                feCNacimientoBox.Text = cliente.fechaNacimiento.ToString();
                sexoBox.Text = cliente.sexo;
                BiometricoBox.Text = cliente.codBiometrico;

                System.IO.MemoryStream stream = new System.IO.MemoryStream(cliente.foto);
                BitmapImage foto = new BitmapImage();
                foto.BeginInit();
                foto.StreamSource = stream;
                foto.CacheOption = BitmapCacheOption.OnLoad;
                foto.EndInit();
                image.Source = foto;
            }
        }
 private void MessageImage(MessageWindowImage messageImage)
 {
     BitmapImage image = new BitmapImage();
     image.BeginInit();
     switch (messageImage)
     { 
         case MessageWindowImage.Error:
             image.UriSource = new Uri("pack://application:,,,/Resources;component/Resources/Error.png");
             break;
         case MessageWindowImage.Warning:
             image.UriSource = new Uri("pack://application:,,,/Resources;component/Resources/Warning.png");
             break;
         case MessageWindowImage.Info:
             image.UriSource = new Uri("pack://application:,,,/Resources;component/Resources/Info.png");
             break;
         case MessageWindowImage.Exit:
             image.UriSource = new Uri("pack://application:,,,/Resources;component/Resources/Exit.png");
             break;
         case MessageWindowImage.Printing:
             image.UriSource = new Uri("pack://application:,,,/Resources;component/Resources/Print.png");
             break;
     }
     image.EndInit();
     Img.Source = image;
 }
Example #47
0
        public static BitmapImage GetCharacterPortrait(Player player)
        {
            if (player == null || player.CharacterID == 0)
                return null;

            int Size = 64;
            string filePath = string.Format("{0}\\{1}.jpg", Utils.PortraitDir, player.CharacterID);

            BitmapImage image = null;
            try
            {
                if (!File.Exists(filePath))
                {

                    WebClient wc = new WebClient();
                    wc.DownloadFile(
                        string.Format("http://img.eve.is/serv.asp?s={0}&c={1}", Size, player.CharacterID),
                        filePath);
                }

                image = new BitmapImage();
                image.BeginInit();
                image.UriSource = new Uri(filePath,
                                          UriKind.Absolute);
                image.EndInit();

            }
            catch (Exception)
            {
            }

            return image;
        }
 public Tuple <BitmapImage, Color> LoadAnimationTexture(string fileName, bool transparent = false)
 {
     if (transparent)
     {
         FileStream            fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
         System.Drawing.Bitmap img        = new System.Drawing.Bitmap(fileStream);
         fileStream.Close();
         var    color = img.Palette.Entries[0];
         string hex   = HexConverter(color);
         img.MakeTransparent(color);
         var finalResult = (BitmapImage)Extensions.BitmapConversion.ToWpfBitmap((System.Drawing.Bitmap)img.Clone());
         img.Dispose();
         return(new Tuple <BitmapImage, Color>(finalResult, (Color)ColorConverter.ConvertFromString(hex)));
     }
     else
     {
         FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
         var        img        = new System.Windows.Media.Imaging.BitmapImage();
         img.BeginInit();
         img.StreamSource = fileStream;
         img.CacheOption  = BitmapCacheOption.OnLoad;
         img.EndInit();
         var finalResult = (BitmapImage)img.Clone();
         fileStream.Close();
         return(new Tuple <BitmapImage, Color>(finalResult, Colors.Black));
     }
 }
Example #49
0
        public MainWindow()
        {
            InitializeComponent();

                // initialize tabItem array
                _tabItems = new List<TabItem>();

                // add a tabItem with + in header
                _tabAdd = new TabItem();
                //get image for header and setup add button
                _tabAdd.Style = new Style();
                _tabAdd.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x30, 0x30, 0x30));
                _tabAdd.BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x30, 0x30, 0x30));
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(@"pack://application:,,,/Explore10;component/Images/appbar.add.png");
                bitmap.EndInit();
                Image plus = new Image();
                plus.Source = bitmap;
                plus.Width = 25;
                plus.Height = 25;
                _tabAdd.Width = 35;
                _tabAdd.Header = plus;
                _tabAdd.MouseLeftButtonUp += new MouseButtonEventHandler(tabAdd_MouseLeftButtonUp);
                _tabItems.Add(_tabAdd);

                // add first tab
                //this.AddTabItem();

                // bind tab control
                tabDynamic.DataContext = _tabItems;

                tabDynamic.SelectedIndex = 0;
        }
Example #50
0
        private void Le_Imagem()
        {
            // ====================================================================
            // Ler Imadem A Partir do Caminho Gravado no "Textnome.Text"...
            // ====================================================================

            try
            {
                FileStream            fs   = File.Open(Textnome.Text, FileMode.Open);
                System.Drawing.Bitmap dImg = new System.Drawing.Bitmap(fs);
                MemoryStream          ms   = new MemoryStream();
                dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                System.Windows.Media.Imaging.BitmapImage bImg = new System.Windows.Media.Imaging.BitmapImage();
                bImg.BeginInit();
                bImg.StreamSource = new MemoryStream(ms.ToArray());
                bImg.EndInit();
                fs.Close();
                fs.Dispose(); // Dispensa da Memória para mostrar outra imagem, para não dar Erro.

                PicFoto.Source = bImg;
            }
            catch (Exception)
            {
                MessageBox.Show("Se a nova Imagem do novo regidtro não Carregou, clique em outra qualquer e de pois volte a clicar nela, faça isso a té que a mesma aparecça normalmente. Isso não é um 'Bug', trata-se de um procedimento interno de sua Máquina para Alocar o novo registro de Imagem em Memóeria, uma vez carregada, não haverá mais Problema algum...", "INFORMAÇÃO IMPORTANTE !!!", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Example #51
0
        public Image GetErrorImageType(int ErrorCode, bool isWarning)
        {
            Image image = new Image()
            {
                Width = 25, Height = 25
            };
            var pic = new System.Windows.Media.Imaging.BitmapImage();

            pic.BeginInit();
            //Image for type of error
            if (ErrorCode == 0 && isWarning)
            {
                pic.UriSource = new Uri("Images/Warning.png", UriKind.Relative);                 // url is from the xml
            }
            else if (ErrorCode != 0)
            {
                pic.UriSource = new Uri("Images/Error.png", UriKind.Relative);                 // url is from the xml
            }
            else
            {
                pic.UriSource = new Uri("Images/CheckMark.png", UriKind.Relative);                 // url is from the xml
            }
            pic.EndInit();
            image.Source = pic;
            return(image);
        }
      public void PageLoaded(object sender, RoutedEventArgs args)
      {
         // Create Image element.
         Image rotated90 = new Image();
         rotated90.Width = 150;

         // Create the TransformedBitmap to use as the Image source.
         TransformedBitmap tb = new TransformedBitmap();

         // Create the source to use as the tb source.
         BitmapImage bi = new BitmapImage();
         bi.BeginInit();
         bi.UriSource = new Uri(@"sampleImages/watermelon.jpg", UriKind.RelativeOrAbsolute);
         bi.EndInit();

         // Properties must be set between BeginInit and EndInit calls.
         tb.BeginInit();
         tb.Source = bi;
         // Set image rotation.
         RotateTransform transform = new RotateTransform(90);
         tb.Transform = transform;
         tb.EndInit();
         // Set the Image source.
         rotated90.Source = tb;

         //Add Image to the UI
         Grid.SetColumn(rotated90, 1);
         Grid.SetRow(rotated90, 1);
         transformedGrid.Children.Add(rotated90);

      }
        public SignatureWindow(string signature)
        {
            var digitalSignatureCollection = new List<object>();
            digitalSignatureCollection.Add(new ComboBoxItem() { Content = "" });
            digitalSignatureCollection.AddRange(Settings.Instance.Global_DigitalSignatureCollection.Select(n => new DigitalSignatureComboBoxItem(n)).ToArray());

            InitializeComponent();

            {
                var icon = new BitmapImage();

                icon.BeginInit();
                icon.StreamSource = new FileStream(Path.Combine(App.DirectoryPaths["Icons"], "Amoeba.ico"), FileMode.Open, FileAccess.Read, FileShare.Read);
                icon.EndInit();
                if (icon.CanFreeze) icon.Freeze();

                this.Icon = icon;
            }

            _signatureComboBox.ItemsSource = digitalSignatureCollection;

            for (int index = 0; index < Settings.Instance.Global_DigitalSignatureCollection.Count; index++)
            {
                if (Settings.Instance.Global_DigitalSignatureCollection[index].ToString() == signature)
                {
                    _signatureComboBox.SelectedIndex = index + 1;

                    break;
                }
            }
        }
        public BitmapImage Convert([CanBeNull] string id) {
            if (id == null) id = @"_";

            BitmapImage bi;
            if (Cache.TryGetValue(id, out bi)) return bi;

            if (_archive == null) {
                _archive = new ZipArchive(new MemoryStream(BinaryResources.Flags));
            }

            var entryStream = (_archive.GetEntry(id) ?? _archive.GetEntry(@"_"))?.Open();
            if (entryStream == null) {
                return null;
            }

            bi = new BitmapImage();
            bi.BeginInit();
            bi.CacheOption = BitmapCacheOption.OnLoad;
            bi.StreamSource = entryStream.ReadAsMemoryStream();
            bi.EndInit();
            bi.Freeze();

            Cache[id] = bi;
            return bi;
        }
Example #55
0
        private void CombineImages(FileInfo[] files)
        {
            //change the location to store the final image.
            string finalImage = panoramaFolder + "FinalImage" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".png";
            int    width      = 0;
            int    height     = 0;

            foreach (FileInfo file in files)
            {
                System.Drawing.Image img = System.Drawing.Image.FromFile(file.FullName);


                width += img.Width;

                height = img.Height > height
                    ? img.Height
                    : height;

                img.Dispose();
            }



            Bitmap   img3 = new Bitmap(width, height);
            Graphics g    = Graphics.FromImage(img3);

            g.Clear(System.Drawing.SystemColors.AppWorkspace);

            width = 0;
            foreach (FileInfo file in files)
            {
                System.Drawing.Image img = System.Drawing.Image.FromFile(file.FullName);

                g.DrawImage(img, new System.Drawing.Point(width, 0));
                width += img.Width;

                img.Dispose();
            }

            g.Dispose();

            img3.Save(finalImage, System.Drawing.Imaging.ImageFormat.Png);
            img3.Dispose();


            System.Windows.Media.Imaging.BitmapImage newImage = new System.Windows.Media.Imaging.BitmapImage();
            newImage.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreImageCache;
            newImage.CacheOption   = System.Windows.Media.Imaging.BitmapCacheOption.None;
            Uri urisource = new Uri(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + finalImage, UriKind.RelativeOrAbsolute);

            newImage.BeginInit();
            newImage.UriSource = urisource;
            newImage.EndInit();
            combineImage.Width  = width / 3;
            combineImage.Height = height / 3;

            combineImage.Source = newImage;
            ///imageLocation.Image = System.Drawing.Image.FromFile(finalImage);
        }
Example #56
0
 public System.Windows.Media.Imaging.BitmapImage ToImageSource(string path)
 {
     System.Windows.Media.Imaging.BitmapImage _bitmap = new System.Windows.Media.Imaging.BitmapImage();
     _bitmap.BeginInit();
     _bitmap.UriSource = new Uri(path);
     _bitmap.EndInit();
     return(_bitmap);
 }
Example #57
0
        public static BitmapImage FileToImage(string FilePath)
        {
            var BI = new System.Windows.Media.Imaging.BitmapImage();

            BI.BeginInit();
            BI.UriSource = new Uri(FilePath, UriKind.RelativeOrAbsolute);
            BI.EndInit();
            return(BI);
        }
Example #58
0
		public override object LoadFromStream (Stream stream)
		{
			var img = new SWMI.BitmapImage ();
			img.BeginInit();
			img.CacheOption = SWMI.BitmapCacheOption.OnLoad;
			img.StreamSource = stream;
			img.EndInit();

			return img;
		}
Example #59
0
        ImageSource createImageFromFIle(string filename)
        {
            MemoryStream stream = new MemoryStream(File.ReadAllBytes(filename));

            System.Windows.Media.Imaging.BitmapImage img = new System.Windows.Media.Imaging.BitmapImage();
            img.BeginInit();
            img.StreamSource = stream;
            img.EndInit();

            return(img);
        }
Example #60
0
        private void ChromelessWindow_Loaded(object sender, RoutedEventArgs e)
        {
            defaults.ShowInTaskBar = true;

            System.Windows.Media.Imaging.BitmapImage bim = new System.Windows.Media.Imaging.BitmapImage();
            bim.BeginInit();
            bim.DecodePixelWidth = 16;
            bim.UriSource        = new Uri("pack://application:,,,/NotifyIcon_2008;Component/Icon.ico");
            bim.EndInit();
            defaults.Icon = bim;
        }