예제 #1
0
 void Jump(object sender, KeyEventArgs e)
 {
     if (e.Key.ToString() == "Space")
     {
         if (!player.fall)
         {
             player.jump = true;
             System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
             bi.BeginInit();
             bi.UriSource = new Uri(path + "jump.png");
             bi.EndInit();
             player.Source = bi;
         }
     }
     if (e.Key.ToString() == "Return")
     {
         if (start)
         {
             if (pause)
             {
                 Unpause();
             }
             else
             {
                 Pause();
             }
         }
     }
 }
예제 #2
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            value = value ?? parameter;

            if (value == null)
            {
                return(null);
            }
            else if (value is Uri)
            {
                var oImage = new System.Windows.Media.Imaging.BitmapImage( );
                oImage.BeginInit( );
                oImage.UriSource = (Uri)value;
                oImage.EndInit( );
                return(oImage);
            }
            else if (value is string)
            {
                var oImage = new System.Windows.Media.Imaging.BitmapImage( );

                oImage.BeginInit( );
                oImage.UriSource = new Uri((string)value, UriKind.RelativeOrAbsolute);
                oImage.EndInit( );
                return(oImage);
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        private System.Windows.Media.Imaging.BitmapSource _UseImage(object imageKey)
        {
            if (_ImagesCache.TryGetValue(imageKey, out System.Windows.Media.Imaging.BitmapSource image))
            {
                return(image);
            }

            var imagePath = imageKey as String;

            using (var s = System.IO.File.OpenRead(imagePath))
            {
                if (true)
                {
                    var img = new System.Windows.Media.Imaging.BitmapImage();

                    img.BeginInit();
                    img.StreamSource = s;
                    img.EndInit();

                    image = img;
                }
                else
                {
                    image = System.Windows.Media.Imaging.BitmapFrame.Create(s, System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreImageCache, System.Windows.Media.Imaging.BitmapCacheOption.None);
                }
            }

            image.Freeze();

            _ImagesCache[imageKey] = image;

            return(image);
        }
예제 #4
0
        public void Draw(System.Windows.Controls.Image imShow, string ImagePath, string XmlPath)
        {
            var   boxes  = helper.GetLabelFromXml(XmlPath);
            Image bitmap = Image.FromFile(ImagePath);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                Font font = new Font("微软雅黑", (float)(bitmap.Width * 0.005) * 2, GraphicsUnit.Pixel);
                foreach (var box in boxes)
                {
                    g.DrawRectangle(new Pen(Color.FromArgb(204, 255, 0), (float)(bitmap.Width * 0.005)), new System.Drawing.Rectangle(box.xmin, box.ymin, box.xmax - box.xmin, box.ymax - box.ymin));
                    var size = g.MeasureString(box.Name, font);
                    g.DrawLine(new Pen(Color.FromArgb(204, 255, 0), (float)(bitmap.Width * 0.005)), box.xmin, box.ymin - (float)(bitmap.Width * 0.005), box.xmin + size.Width, box.ymin - (float)(bitmap.Width * 0.005));
                }
                foreach (var box in boxes)
                {
                    g.DrawString(box.Name, font, new SolidBrush(Color.Black), new PointF(box.xmin, box.ymin - (float)(bitmap.Width * 0.01)));
                }
            }
            MemoryStream memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Png);
            System.Windows.Media.Imaging.BitmapImage Bimage = new System.Windows.Media.Imaging.BitmapImage();
            Bimage.BeginInit();
            memoryStream.Seek(0, SeekOrigin.Begin);
            Bimage.StreamSource = memoryStream;
            Bimage.EndInit();
            imShow.Source = Bimage;
        }
        public override UIElement BuildElement(DisplayBlock.DisplayBlock displayBlock)
        {
            var pictureBlock = displayBlock as DisplayBlock.PictureBlock;
            var bitmap       = new Media.Imaging.BitmapImage();

            using (var ms = new MemoryStream(Convert.FromBase64String(pictureBlock.Details.Base64Image)))
            {
                bitmap.BeginInit();
                bitmap.CacheOption  = Media.Imaging.BitmapCacheOption.OnLoad; // here
                bitmap.StreamSource = ms;
                bitmap.EndInit();
            }

            var image = new Image
            {
                Height  = pictureBlock.Height,
                Width   = pictureBlock.Width,
                Source  = bitmap,
                Stretch = Media.Stretch.None
            };

            Canvas.SetTop(image, pictureBlock.Top);
            Canvas.SetLeft(image, pictureBlock.Left);
            Panel.SetZIndex(image, pictureBlock.ZIndex);
            return(image);
        }
예제 #6
0
        /// <summary>
        /// Gets the WPF bitmap image.
        /// </summary>
        internal System.Windows.Media.Imaging.BitmapImage GetWpfBitmapImage(IconCollectionInfo collectionInfo, IconFileInfo fileInfo)
        {
            string iconFileKey = GetIconFileKey(collectionInfo, fileInfo);

            // Load the ImageSource (me may have cached it before
            System.Windows.Media.Imaging.BitmapImage result = null;
            if (!m_wpfBitmapImages.TryGetValue(iconFileKey, out result))
            {
                // Try to load the icon from png file
                var pngIconLink = TryFindPngIcon(collectionInfo, fileInfo);
                if (pngIconLink != null)
                {
                    using (Stream inStream = pngIconLink.OpenRead())
                    {
                        result = new System.Windows.Media.Imaging.BitmapImage();
                        result.BeginInit();
                        result.StreamSource = inStream;
                        result.EndInit();
                        result.Freeze();
                    }
                }

                m_wpfBitmapImages.Add(iconFileKey, result);
            }

            return(result);
        }
 private void typesComboBox_DropDownClosed(object sender, System.EventArgs e)
 {
     if (typesComboBox.Text != "")
     {
         if (CntrlPnl.Children.Count > 0)
         {
             CntrlPnl.Children.RemoveAt(0);
         }
         Types.AvailablePlugin selectedPlugin = GlobalUserControls.OSAEUserControls.AvailablePlugins.Find(typesComboBox.Text.ToString());
         PluginName.Content = selectedPlugin.Instance.Name;
         PluginDesc.Content = selectedPlugin.Instance.Description;
         PluginVersion.Content = selectedPlugin.Instance.Version;
         PluginAuthor.Content = selectedPlugin.Instance.Author;
         int lastslash = selectedPlugin.AssemblyPath.ToString().LastIndexOf(@"\");
         string imgURI = selectedPlugin.AssemblyPath.ToString().Substring(0, lastslash + 1);
         imgURI = imgURI + "ScreenShot.jpg";
         System.Windows.Media.Imaging.BitmapImage pluginImg = new System.Windows.Media.Imaging.BitmapImage();
         pluginImg.BeginInit();
         pluginImg.UriSource = new System.Uri(imgURI);
         pluginImg.EndInit();
         PluginImg.Source = pluginImg;
         selectedPlugin.Instance.InitializeAddCtrl(currentScreen,selectedPlugin.Instance.Name,currentUser);
         UserControl addcontrol = selectedPlugin.Instance.CtrlInterface;
         if (addcontrol.Height > CntrlPnl.Height)
         {
             double cH = addcontrol.Height - CntrlPnl.Height;
             this.Height = this.Height + cH + 80;
             CntrlPnl.Height = addcontrol.Height + 80;
         }
         CntrlPnl.Children.Add(addcontrol);
     }
 }
예제 #8
0
        private void WriteBarcode()
        {
            Image image = new Image();

            image.Width  = 100;
            image.Height = 100;
            string containerId = $"CTNR{this.m_ClientOrder.ClientOrderDetailCollection[0].ContainerId}";

            DataMatrix.net.DmtxImageEncoder encoder = new DataMatrix.net.DmtxImageEncoder();
            System.Drawing.Bitmap           bitmap  = encoder.EncodeImage(containerId);

            using (var ms = new System.IO.MemoryStream())
            {
                bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                ms.Seek(0, System.IO.SeekOrigin.Begin);

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

                image.Source = bitmapImage;
            }

            Grid.SetColumn(image, 2);
            Grid.SetRowSpan(image, 10);
            Grid.SetRow(image, 2);
            this.m_PatientInfoGrid.Children.Add(image);
        }
예제 #9
0
        private void VideoForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.timer1.Stop();

            if (ChatClient.Login._UserInfo.Kind == (int)ChatEngine.UserKind.ServiceWoman)
            {
                StopSend();
                StopAudioCapture();
                StopVideoCapture();
                m_mainWnd.soloVideoForm = null;
                ChatClient.Login._UserInfo.nUserState = 22;
                ChatClient.Login._ClientEngine.Send(ChatEngine.NotifyType.Request_UserState, ChatClient.Login._UserInfo);

                System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri("/Resources;component/image/novideo.png", UriKind.RelativeOrAbsolute);
                bi.EndInit();

                m_mainWnd.imgCamOrNotify.Source = bi;
            }
            else
            {
                StringBuilder strFriendID = new StringBuilder(this.friendID);
                StopReceive(strFriendID);
            }
        }
        private void ShowPreview()
        {
            int  count = SampleId;
            Card c     = Program.CardManager.Cardlist[count];

            try
            {
                System.Drawing.Bitmap img = Program.CardManager.Creator.CreateBitmap(c, CurrentTemplate);
                Program.CardManager.Creator.EndInit();

                using (MemoryStream memory = new MemoryStream())
                {
                    img.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
                    memory.Position = 0;
                    System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = memory;
                    bitmapImage.CacheOption  = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();

                    Preview.Source = bitmapImage;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                Program.CardManager.Creator.EndInit();
            }
        }
예제 #11
0
        public void LoadFile()
        {
            var files = Common.BrowseForFiles("PDF (*.pdf)|*.pdf|PNG (*.png)|*.png");

            if (files.ShowDialog() != true)
            {
                return;
            }
            var fileInfo = new FileInfo(files.FileName);

            FilePath = files.FileName;
            if (fileInfo.Extension == ".pdf")
            {
                if (string.IsNullOrWhiteSpace(PdfPageNumber))
                {
                    return;
                }
                PageNumber = Convert.ToInt32(PdfPageNumber);
                var imgPath = ConvertPdfToImage(fileInfo.FullName);
                FilePath = imgPath;
            }
            var bmp = new System.Windows.Media.Imaging.BitmapImage();

            bmp.BeginInit();
            bmp.UriSource = new Uri(FilePath);
            bmp.EndInit();
            var width  = Convert.ToInt32(bmp.Width);
            var height = Convert.ToInt32(bmp.Height);

            ImageSize   = new Size(width, height);
            ImageSource = bmp;
        }
예제 #12
0
        /// <summary>
        /// Redraws the layer using the last calculated coordinates.
        /// </summary>
        private async void RefreshLayer()
        {
            try
            {
                //Ground resolution at equator
                var groudResolution = (2 * Math.PI * 6378135) / Math.Round(256 * Math.Pow(2, _map.ZoomLevel));
                var radiusInPixels  = _radius / groudResolution;

                if (radiusInPixels < _minRadius)
                {
                    radiusInPixels = _minRadius;
                }

                using (var ms = await _renderEngine.RenderData(_points, _style, (int)radiusInPixels, (int)Math.Ceiling(this.Width), (int)Math.Ceiling(this.Height)))
                {
                    if (ms != null)
                    {
                        ms.Position = 0;
                        var bmp = new System.Windows.Media.Imaging.BitmapImage();
                        bmp.BeginInit();
                        bmp.CacheOption  = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                        bmp.StreamSource = ms;
                        bmp.EndInit();

                        _img.Source     = bmp;
                        _img.Visibility = Visibility.Visible;
                    }
                }
            }
            catch { }
        }
        /// <summary>
        /// Convert the value
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object ret = null;
            string res = value as string;

            try
            {
#if SILVERLIGHT
                ret = res;
#else
                if (!string.IsNullOrEmpty(res))
                {
                    System.Windows.Media.Imaging.BitmapImage bs = new System.Windows.Media.Imaging.BitmapImage();
                    bs.BeginInit();
                    bs.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                    bs.UriSource   = new Uri(res);
                    bs.EndInit();
                    ret = bs;
                }
#endif
            }
            catch
            {
            }

            return(ret);
        }
예제 #14
0
        public void SetType(PieceType type)
        {
            this.Type = type;

            pieceImaging = null;
            pieceImaging = new System.Windows.Media.Imaging.BitmapImage();
            Bitmap tile = this.Color == PieceColor.WHITE ? tileWhites : tileBlack;

            pieceImage = tile.Clone(new Rectangle(((int)this.Type) * 75, 0, 75, 75),
                                    System.Drawing.Imaging.PixelFormat.DontCare);

            byte[] data;
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            pieceImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Position = 0;
            data            = new byte[stream.Length];
            stream.Read(data, 0, data.Length);

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

            this.Source = pieceImaging;
            //stream.Close();
        }
예제 #15
0
            public object Convert(object value, Type targetType,
                                  object parameter, CultureInfo culture)
            {
                // empty images are empty...
                if (value == null)
                {
                    return(null);
                }

                try
                {
                    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();
                    MemoryStream memoryStream = new MemoryStream();
                    // Save to a memory stream...
                    //image.Save("C:\\falconOut\\Falcon.bmp");

                    image.Save(memoryStream, ImageFormat.Bmp);
                    // Rewind the stream...
                    //memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                    bitmap.StreamSource = memoryStream;
                    bitmap.EndInit();
                    return(bitmap);
                }
                catch (Exception ex)
                {
                    DynamoLogger.Instance.Log(ex.Message);
                    DynamoLogger.Instance.Log(ex.StackTrace);
                    return(null);
                }
            }
예제 #16
0
        static void Main(string[] args)
        {
            var image1 = System.Drawing.Image.FromFile("tumblr_mwiiixNSpW1qbkusho1_1280.png");
            //Debugger.Break();

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

            image2.BeginInit();
            image2.UriSource = new System.Uri("tumblr_mwiiixNSpW1qbkusho1_1280.png", System.UriKind.Relative);
            image2.EndInit();
            //Debugger.Break();

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

            image3.BeginInit();
            image3.StreamSource = new System.IO.FileStream("VisualStudio256_256.png", System.IO.FileMode.Open);
            image3.EndInit();
            //Debugger.Break();

            var pixelFormat = System.Windows.Media.PixelFormats.Bgr32;
            int width       = 1280;
            int height      = 720;
            int rawStride   = (width * pixelFormat.BitsPerPixel + 7) / 8;

            byte[] rawImage = new byte[rawStride * height];
            var    value    = new System.Random();

            value.NextBytes(rawImage);

            var image4 = System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96, pixelFormat, null, rawImage, rawStride);

            System.Diagnostics.Debugger.Break();
        }
        public void addMarkerImage(int id, double lat, double lon, string filename, string type)
        {
            PointLatLng point = new PointLatLng(lat, lon);

            try
            {
                System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.UriSource = new Uri(filename);
                bitmapImage.EndInit();
                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Source = bitmapImage;
                GMapMarker marker = new GMapMarker(point);
                image.Width  = 50;
                image.Height = 50;
                markers[id]  = marker;

                marker.Tag   = id.ToString() + ":" + type + " :";
                marker.Shape = image;
                mapView.Markers.Add(marker);
            }
            catch (Exception e)
            {
            }
        }
예제 #18
0
        public static System.Windows.Controls.Image ConvertImageToWpfImage(System.Drawing.Image image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image", "Image darf nicht null sein.");
            }

            using (System.Drawing.Bitmap dImg = new System.Drawing.Bitmap(image))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

                    System.Windows.Media.Imaging.BitmapImage bImg = new System.Windows.Media.Imaging.BitmapImage();

                    bImg.BeginInit();
                    bImg.StreamSource = new MemoryStream(ms.ToArray());
                    bImg.EndInit();

                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
                    img.Source = bImg;

                    return(img);
                }
            }
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(System.Windows.Media.ImageSource))
            {
                if (value == null)
                {
                    return(null);
                }

                System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();

                Bitmap       bm = value as Bitmap;
                MemoryStream ms = new MemoryStream();
                bm.Save(ms, ImageFormat.Png);
                ms.Seek(0, SeekOrigin.Begin);

                bi.BeginInit();
                bi.StreamSource = ms;
                bi.EndInit();

                return(bi);
            }
            else
            {
                return((string)value);
            }
        }
        private Media.Brush MergeAttribsAndCArd(Drawing.Bitmap attribsBitmap, Drawing.Bitmap cardBitmap)
        {
            var bitmap = new Drawing.Bitmap(160 + 269, 44);

            using (Drawing.Graphics g = Drawing.Graphics.FromImage(bitmap))
            {
                g.DrawImage(attribsBitmap, 0, 0);
                g.DrawImage(cardBitmap, 160, 0, 265, 44);
            }

            using (MemoryStream memory = new MemoryStream())
            {
                bitmap.Save(memory, Drawing.Imaging.ImageFormat.Png);
                memory.Position = 0;
                var bitmapImage = new Media.Imaging.BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption  = Media.Imaging.BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
                return(new Media.ImageBrush(bitmapImage)
                {
                    Stretch = Media.Stretch.Fill
                });
            }
        }
예제 #21
0
        static internal Media.Imaging.BitmapImage LoadBitmapImage(this Assembly assembly, string name, bool small = false)
        {
            using (var resource = assembly.GetManifestResourceStream(name))
            {
                var bitmapImage = new Media.Imaging.BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = resource;
                bitmapImage.EndInit();

                int desiredSize = small ? 16 : 32;
                if ((int)bitmapImage.Height != desiredSize || (int)bitmapImage.Width != desiredSize)
                {
                    var scaledBitmapImage = new Media.Imaging.BitmapImage();
                    scaledBitmapImage.BeginInit();
                    scaledBitmapImage.StreamSource      = resource;
                    scaledBitmapImage.DecodePixelWidth  = (int)Math.Round(bitmapImage.PixelWidth * (desiredSize / bitmapImage.Width));
                    scaledBitmapImage.DecodePixelHeight = (int)Math.Round(bitmapImage.PixelHeight * (desiredSize / bitmapImage.Height));
                    scaledBitmapImage.EndInit();

                    return(scaledBitmapImage);
                }

                return(bitmapImage);
            }
        }
예제 #22
0
파일: Photo.cs 프로젝트: lqq200901/GDXJ2016
        public static ImageSource GetPhoto(ref CookieContainer cookie, string studentId, string name)
        {
            string downloadPath = url.domainUrl + @"/fileDownload?fileName=&filePath={0}&project=0 ";
            string refererUrl   = url.domainUrl + @"/jsp/mems/xsxxgl/xjqgl/jlxjq.jsp?xsJbxxId={0}&xm={1}";

            System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage();
            try
            {
                string path    = string.Format(downloadPath, GetPhotoPath(ref cookie, studentId));
                string referer = string.Format(refererUrl, studentId, QQLib.Encoded.Url.UrlEncode(name));
                image.BeginInit();

                var req = Http.Get(path);
                req.AddHeader("Referer", referer);
                //req.AddHeader("_ccrf.token", Csrf.GetCsrfToken());

                image.StreamSource = req.RealTimeGo().RequestStream;
                image.EndInit();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                //throw (new Exception("Get VerificationCodeImage error!"));
            }
            return(image);
        }
예제 #23
0
 private void typesComboBox_DropDownClosed(object sender, System.EventArgs e)
 {
     if (typesComboBox.Text != "")
     {
         if (CntrlPnl.Children.Count > 0)
         {
             CntrlPnl.Children.RemoveAt(0);
         }
         Types.AvailablePlugin selectedPlugin = GlobalUserControls.OSAEUserControls.AvailablePlugins.Find(typesComboBox.Text.ToString());
         PluginName.Content    = selectedPlugin.Instance.Name;
         PluginDesc.Content    = selectedPlugin.Instance.Description;
         PluginVersion.Content = selectedPlugin.Instance.Version;
         PluginAuthor.Content  = selectedPlugin.Instance.Author;
         int    lastslash = selectedPlugin.AssemblyPath.ToString().LastIndexOf(@"\");
         string imgURI    = selectedPlugin.AssemblyPath.ToString().Substring(0, lastslash + 1);
         imgURI = imgURI + "ScreenShot.jpg";
         System.Windows.Media.Imaging.BitmapImage pluginImg = new System.Windows.Media.Imaging.BitmapImage();
         pluginImg.BeginInit();
         pluginImg.UriSource = new System.Uri(imgURI);
         pluginImg.EndInit();
         PluginImg.Source = pluginImg;
         selectedPlugin.Instance.InitializeAddCtrl(currentScreen, selectedPlugin.Instance.Name, currentUser);
         UserControl addcontrol = selectedPlugin.Instance.CtrlInterface;
         if (addcontrol.Height > CntrlPnl.Height)
         {
             double cH = addcontrol.Height - CntrlPnl.Height;
             this.Height     = this.Height + cH + 80;
             CntrlPnl.Height = addcontrol.Height + 80;
         }
         CntrlPnl.Children.Add(addcontrol);
     }
 }
예제 #24
0
        //#endregion

        private void ManVideoFormcs_Load(object sender, EventArgs e)
        {
            if (m_mainWnd != null)
            {
                int nScreenWidth  = SystemInformation.VirtualScreen.Width;
                int nScreenHeight = SystemInformation.VirtualScreen.Height;
                if (m_mainWnd.Left + m_mainWnd.Width + this.Width > nScreenWidth)
                {
                    this.Left = nScreenWidth - this.Width;
                }
                else
                {
                    this.Left = (int)(m_mainWnd.Left + m_mainWnd.Width + 5);
                }

                this.Top = (int)m_mainWnd.Top;
            }

            if (ChatClient.Login._UserInfo.Kind == (int)ChatEngine.UserKind.ServiceWoman)
            {
                System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri("/Resources;component/image/video.png", UriKind.RelativeOrAbsolute);
                bi.EndInit();

                m_mainWnd.imgCamOrNotify.Source = bi;
            }
        }
        /// <summary>
        /// Convert the value
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object ret = null;
            string res = value as string;

            try
            {

            #if SILVERLIGHT
                ret = res;
            #else
                if (!string.IsNullOrEmpty(res))
                {
                    System.Windows.Media.Imaging.BitmapImage bs = new System.Windows.Media.Imaging.BitmapImage();
                    bs.BeginInit();
                    bs.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                    bs.UriSource = new Uri(res);
                    bs.EndInit();
                    ret = bs;
                }
            #endif
            }
            catch
            {
            }

            return (ret);
        }
        private void SetPreviewImage()
        {
            Bitmap       previewBitmap = new Bitmap(50, 50);
            Graphics     previewCanvas = Graphics.FromImage(previewBitmap);
            MemoryStream previewStream = new MemoryStream();

            try
            {
                previewCanvas.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, 50, 50),
                                                                                             SelectedBrush.StartColor,
                                                                                             SelectedBrush.EndColor,
                                                                                             (float)SelectedBrush.Angle), new Rectangle(0, 0, 50, 50));

                previewBitmap.Save(previewStream, System.Drawing.Imaging.ImageFormat.Png);
                System.Windows.Media.Imaging.BitmapImage imageSource = new System.Windows.Media.Imaging.BitmapImage();
                imageSource.BeginInit();
                imageSource.StreamSource = previewStream;
                imageSource.EndInit();

                PreviewImage = imageSource;
            }
            catch (Exception ex)
            {
                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
            }
            finally
            {
                previewBitmap.Dispose();
            }

            if (!stopColorChangedEvent)
            {
                OnSelectedBrushChanged();
            }
        }
        /// <summary>
        /// Convert Bitmap to BitmapImage
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static System.Windows.Media.Imaging.BitmapImage Bitmap2Bitmapimage(System.Drawing.Bitmap input)
        {
            System.Windows.Media.Imaging.BitmapImage retval = new System.Windows.Media.Imaging.BitmapImage();
            if (input == null)
            {
                return(retval);
            }

            IntPtr hBitmap = input.GetHbitmap();

            try
            {
                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    input.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    ms.Position = 0;

                    retval.BeginInit();
                    // According to MSDN, "The default OnDemand cache option retains access to the stream until the image is needed."
                    // Force the bitmap to load right now so we can dispose the stream.
                    retval.CacheOption  = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                    retval.StreamSource = ms;
                    retval.EndInit();
                    retval.Freeze();
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("In ImageTypeConverter.Bitmap2Bitmapimage" + ex.Message);
            }

            return(retval);
        }
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            // empty images are empty...
            if (value == null)
            {
                return(null);
            }


            //var image = value as System.Drawing.Bitmap;

            System.Drawing.Bitmap image = (System.Drawing.Bitmap)value;

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

            // 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);
        }
예제 #29
0
        static void Main()
        {
            var image1 = System.Drawing.Image.FromFile("tumblr_mwiiixNSpW1qbkusho1_1280.png");

            var visualizerHost = new VisualizerDevelopmentHost(image1, typeof(ImageVisualizer.Visualizer));

            visualizerHost.ShowVisualizer();
            var debuggeeObject = visualizerHost.DebuggeeObject;

            Debugger.Break();


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

            image2.BeginInit();
            image2.UriSource = new Uri("tumblr_mwiiixNSpW1qbkusho1_1280.png", UriKind.Relative);
            image2.EndInit();

            visualizerHost = new VisualizerDevelopmentHost(image2, typeof(ImageVisualizer.Visualizer), typeof(ImageVisualizer.ImageVisualizerObjectSource));
            visualizerHost.ShowVisualizer();

            Debugger.Break();


            var image2small = new System.Windows.Media.Imaging.BitmapImage(); //new Uri("VisualStudio256_256.png", UriKind.Relative));

            image2small.BeginInit();
            image2small.StreamSource = new FileStream("VisualStudio256_256.png", FileMode.Open);
            image2small.EndInit();

            visualizerHost = new VisualizerDevelopmentHost(image2small, typeof(ImageVisualizer.Visualizer), typeof(ImageVisualizer.ImageVisualizerObjectSource));
            visualizerHost.ShowVisualizer();

            Debugger.Break();
        }
        /// <summary>
        /// Loads all the resources.
        /// </summary>
        internal static void LoadResources()
        {
            var currentAssembly = typeof(ProgramResourceManager).Assembly;
            var resourceNames   = currentAssembly.GetManifestResourceNames();

            foreach (var resourceName in resourceNames)
            {
                if (System.Linq.Enumerable.Any(ImageResourcesType, ext => resourceName.EndsWith(ext)))
                {
                    var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                    using (var stream = currentAssembly.GetManifestResourceStream(resourceName))
                    {
                        bitmapImage.BeginInit();
                        bitmapImage.CacheOption  = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                        bitmapImage.StreamSource = stream;
                        bitmapImage.EndInit();
                    }
                    Resources[resourceName] = bitmapImage;
                }
                else
                {
                    throw new System.NotSupportedException($"A resource of type '{resourceName}' is not supported in a BaZic program.");
                }
            }
        }
예제 #31
0
            public Task LoadImageControl()
            {
                TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

                app.Dispatcher.Invoke(async() =>
                {
                    Image img = new Image()
                    {
                        Stretch = System.Windows.Media.Stretch.Fill, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center
                    };

                    img.LayoutUpdated += (s, e) =>
                    {
                        if (img.ActualWidth > 0)
                        {
                            tcs.TrySetResult(null);
                        }
                    };
                    TaskCompletionSource <object> tcs2 = new TaskCompletionSource <object>();
                    img.Loaded            += (s, e) => tcs.SetResult(null);
                    app.MainWindow.Content = img;
                    await tcs.Task;
                    var imageSource           = new System.Windows.Media.Imaging.BitmapImage();
                    imageSource.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.DelayCreation;
                    imageSource.CacheOption   = System.Windows.Media.Imaging.BitmapCacheOption.None;
                    imageSource.BeginInit();
                    imageSource.UriSource = new Uri("image.jpg", UriKind.Relative);
                    imageSource.EndInit();
                    img.Source = imageSource;
                });
                return(tcs.Task);
            }
예제 #32
0
파일: ImageSource.cs 프로젝트: bl0rq/Utilis
		public object Convert ( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
		{
			value = value ?? parameter;

			if ( value == null )
				return null;
			else if ( value is Uri )
			{
				var oImage = new System.Windows.Media.Imaging.BitmapImage ( );
				oImage.BeginInit ( );
				oImage.UriSource = (Uri)value;
				oImage.EndInit ( );
				return oImage;
			}
			else if ( value is string )
			{
				var oImage = new System.Windows.Media.Imaging.BitmapImage ( );

				oImage.BeginInit ( );
				oImage.UriSource = new Uri ( (string)value, UriKind.RelativeOrAbsolute );
				oImage.EndInit ( );
				return oImage;
			}
			else
				return null;
		}
예제 #33
0
 public static System.Windows.Media.Imaging.BitmapImage LoadImageSource(string uri)
 {
     System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
     bi.BeginInit();
     bi.StreamSource = GetStreamFromFile(uri);
     bi.EndInit();
     return(bi);
 }
 public static void LoadUrl(this Image img,string url)
 {
     System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
     bi.BeginInit();
     bi.StreamSource = HttpWebRequest.Create(url).GetResponse().GetResponseStream();
     bi.EndInit();
     img.Source = bi;
 }
예제 #35
0
		public void LoadFromUrl(Uri url)
		{
			var bitmap = new System.Windows.Media.Imaging.BitmapImage();
			bitmap.BeginInit();
			bitmap.UriSource = url;
			bitmap.EndInit();

			InnerImage.Source = bitmap;
		}
예제 #36
0
		public void LoadFromStream(Stream stream)
		{
			var bitmap = new System.Windows.Media.Imaging.BitmapImage();
			bitmap.BeginInit();
			bitmap.StreamSource = stream;
			bitmap.EndInit();

			InnerImage.Source = bitmap;
		}
        public static System.Windows.Media.Imaging.BitmapImage GetImageFromFile( string path )
        {
            System.Windows.Media.Imaging.BitmapImage img = new System.Windows.Media.Imaging.BitmapImage ();
            img.BeginInit ();
            img.UriSource = new System.Uri (path, System.UriKind.RelativeOrAbsolute);
            img.EndInit ();

            return img;
        }
예제 #38
0
        public static System.Windows.Media.Imaging.BitmapImage GetBitmapFromFile(string path)
        {
            System.Windows.Media.Imaging.BitmapImage img = new System.Windows.Media.Imaging.BitmapImage();
            img.BeginInit();
            // Every path can be represented by an URI
            img.UriSource = new System.Uri(path, System.UriKind.RelativeOrAbsolute);
            img.EndInit();

            return img;
        }
 public JobActivityGroupViewModel(JobContainerViewModel container, ActivityInfo activityInfo, Model.ImageDownloader[] imageDownloader)
 {
     NoticeText = activityInfo.PostUser.Name;
     NoticeIcon = new System.Windows.Media.Imaging.BitmapImage();
     NoticeIcon.BeginInit();
     NoticeIcon.DecodePixelWidth = 25;
     NoticeIcon.UriSource = activityInfo.PostUser.IconImageUrl;
     NoticeIcon.EndInit();
     ActivityUrl = activityInfo.PostUrl;
     DownloadImageJobs = imageDownloader.Select(
         downloader => (JobViewModelBase)new JobViewModel(container, downloader)).ToList();
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            BinaryResource resource = value as BinaryResource;
            if (resource == null)
                return null;

            MemoryStream tempStream = new MemoryStream(resource.Buffer);
            var tempIcon = new System.Windows.Media.Imaging.BitmapImage();
            tempIcon.BeginInit();
            tempIcon.StreamSource = tempStream;
            tempIcon.EndInit();

            return tempIcon;
        }
예제 #41
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) { return null; }

            var image = (System.Drawing.Image)value;
            var bitmap = new System.Windows.Media.Imaging.BitmapImage();
            bitmap.BeginInit();
            MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, image.RawFormat);
            memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
            bitmap.StreamSource = memoryStream;
            bitmap.EndInit();
            return bitmap;
        }
예제 #42
0
        System.Windows.Media.Imaging.BitmapImage BitmapToImageSource(Bitmap bitmap)
        {
            using (MemoryStream memory = new MemoryStream())
            {
                bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
                memory.Position = 0;
                System.Windows.Media.Imaging.BitmapImage bitmapimage = new System.Windows.Media.Imaging.BitmapImage();
                bitmapimage.BeginInit();
                bitmapimage.StreamSource = memory;
                bitmapimage.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                bitmapimage.EndInit();

                return bitmapimage;
            }
        }
예제 #43
0
        public static System.Windows.Media.Imaging.BitmapImage ImageToImageSource(System.Drawing.Image image)
        {
            if (image == null) 
                return null;

            var bitmap = new System.Windows.Media.Imaging.BitmapImage();
            bitmap.BeginInit();
            MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, ImageFormat.Bmp);
            memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
            bitmap.StreamSource = memoryStream;
            bitmap.EndInit();

            return bitmap;
        }
예제 #44
0
 public static System.Windows.Media.Imaging.BitmapImage ConvertImage(Image image)
 {
     //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();
     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;
 }
예제 #45
0
        public void LoadFile(string fileName)
        {
            // BCFFile retFile = new BCFFile();
            using (ZipFile z = ZipFile.Read(fileName))
            {
                Regex r = new Regex(@"(?<guid>.*?)/(?<fname>.*)");
                foreach (var zipentry in z)
                {
                    string tFName = System.IO.Path.GetTempFileName();
                    var res = r.Match(zipentry.FileName);
                    if (res.Success)
                    {
                        using (BinaryWriter writer = new BinaryWriter(File.Open(tFName, FileMode.Create)))
                        {
                            zipentry.Extract(writer.BaseStream);
                        }

                        string guid = res.Groups["guid"].Value;
                        string fname = res.Groups["fname"].Value;
                        if (!Instances.Where(x=>x.Markup.Topic.Guid == guid).Any())
                            Instances.Add(new BcfInstance(guid));

                        BcfInstance inst = Instances.Where(x => x.Markup.Topic.Guid == guid).FirstOrDefault();
                        switch (fname.ToLowerInvariant())
                        {
                            case MarkupFileName:
                                inst.Markup = Markup.LoadFromFile(tFName);
                                break;
                            case ViewpointFileName:
                                inst.VisualizationInfo = VisualizationInfo.LoadFromFile(tFName);
                                break;
                            case SnapshotFileName:
                                var bi = new System.Windows.Media.Imaging.BitmapImage();
                                bi.BeginInit();
                                bi.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                                bi.UriSource = new Uri(tFName);
                                bi.EndInit();
                                inst.SnapShot = bi;
                                break;
                            default:
                                break;
                        }
                        File.Delete(tFName);
                    }
                }    
            }
        }
예제 #46
0
        public System.Windows.Controls.Image ByteToWPFImage(byte[] blob)
        {
            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();
            System.Windows.Controls.Image image2 = new System.Windows.Controls.Image() { Source = bi };
            return image2;
        }
        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();
            MemoryStream memoryStream = new MemoryStream();
            // Save to a memory stream…
            image.Save(memoryStream, image.RawFormat);
            // Rewind the stream…
            memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
            bitmap.StreamSource = memoryStream;
            bitmap.EndInit();
            return bitmap;
        }
예제 #48
0
        /// <summary>
        /// Using Windows.Data.Pdf in desktop applications
        /// </summary>
        private async Task<System.Windows.Media.Imaging.BitmapImage> renderPage()
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var winrtStream = memoryStream.AsRandomAccessStream())
                {
                    using (var page = _pdfDocument.GetPage(_currentPageIndex))
                    {
                        await page.RenderToStreamAsync(winrtStream);
                        await winrtStream.FlushAsync();

                        var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                        bitmapImage.BeginInit();
                        //Without this, BitmapImage uses lazy initialization by default and the stream will be closed by then.
                        bitmapImage.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                        bitmapImage.StreamSource = memoryStream;
                        bitmapImage.EndInit();

                        return bitmapImage;
                    }
                }
            }
        }
예제 #49
0
        private static System.Windows.Media.Imaging.BitmapImage GetBitmap(List<RequestedTileInformation> tis)
        {
            System.Windows.Media.Imaging.BitmapImage result = null;
            bool valid = true;

            if (tis[0].Zoom == tis[0].mapFile.MapFileHandler.MapControlFactory.LastRequestedZoomLevel)
            {
                using (System.Drawing.Bitmap img = new System.Drawing.Bitmap(256, 256))
                {
                    img.SetResolution(96, 96);
                    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                        g.Clear(System.Drawing.ColorTranslator.FromHtml("#f1eee8"));
                        valid = valid && drawWays(tis, g);
                        valid = valid && drawPOIs(tis, g);
                    }
                    if (valid)
                    {
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                        {
                            img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            ms.Position = 0;

                            result = new System.Windows.Media.Imaging.BitmapImage();
                            result.BeginInit();
                            result.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                            result.StreamSource = ms;
                            result.EndInit();
                            result.Freeze();
                        }
                    }
                }
            }
            return result;
        }
		static System.Windows.Media.Imaging.BitmapImage BitmapFromImage(ExportImage image)
		{
			var bitmap = new System.Windows.Media.Imaging.BitmapImage();
			bitmap.BeginInit();
			MemoryStream memoryStream = new MemoryStream();
			image.Image.Save(memoryStream, ImageFormat.Bmp);
			memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
			bitmap.StreamSource = memoryStream;
			bitmap.EndInit();
			return bitmap;
		}
예제 #51
0
        private void SaveTemplate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //prepare rule representation
                StackPanel sp = new StackPanel();//testing new rule representation
                sp.Orientation = Orientation.Horizontal;

                Image arrowImage = new Image();
                arrowImage.Width = 50;
                arrowImage.Height = 30;
                // Create source.
                System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();

                // BitmapImage.UriSource must be in a BeginInit/EndInit block.
                bi.BeginInit();
                bi.UriSource = new Uri(@"/Images/doubleArrow.gif", UriKind.RelativeOrAbsolute);
                bi.EndInit();

                // Set the image source.
                arrowImage.Source = bi;

                sp.Children.Add(renderer.render(LHS.Clone() as VisualElement));
                sp.Children.Add(arrowImage);
                sp.Children.Add(renderer.render(RHS.Clone() as VisualElement));

                ruleContent = new ContentPresenter();
                ruleContent.Content = sp;

                saveTemplate();

                RuleDesignerCanvas.Children.Clear();
                RuleDesignStatusBar.clearReportMessage();
            }
            catch (Exception ex)
            {
                ReportStatusBar.ShowStatus(ex.ToString(), ReportIcon.Error);
            }
        }
예제 #52
0
        internal void FetchImage()
        {
            if (BookImageUrl != null)
            {
                if (_imgcache == null)
                {
                    try
                    {
                        System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
                        bi.BeginInit();

                        var res = HttpWebRequest.Create(BookImageUrl).GetResponse();
                        var str =  res.GetResponseStream();
                        bi.StreamSource = str;
                        bi.EndInit();
                        bi.Freeze();

                        str.Close();
                        str.Dispose();

                        _imgcache = bi;
                        BookImageFld = bi;
                    }
                    catch (Exception)
                    {
                        BookImageFld = null;
                    }
                }
                else
                    BookImageFld = _imgcache;
            }
        }
예제 #53
0
        public byte[,] GetMap()
        {
            Bitmap bmp = new Bitmap(size.Width, size.Height);
            Graphics g = Graphics.FromImage(bmp);
            g.Clear(Color.White);
            for (int n = 0; n < PaintObjectList.Count; n++)
            {
                if (PaintObjectList[n].GetName() == "path")
                {
                    string data;
                    if (!PaintObjectList[n].TryGetAttributeValue("data", out data))
                    {
                        continue;
                    }
                    string[] val = data.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    PointF currentPoint = new PointF();
                    SVSObjectStyle style = PaintObjectList[n].GetStyle();
                    GraphicsPath path = new GraphicsPath();
                    for (int i = 0; i < val.Length; i++)
                    {
                        if (val[i] == "m")
                        {
                            i++;
                            currentPoint = StringToPoint(val[i]);
                            while (i < val.Length - 1)
                            {
                                if (val[i + 1].Length == 1)
                                {
                                    break;
                                }
                                i++;
                                PointF nextPoint = StringToPoint(val[i]);
                                nextPoint.X += currentPoint.X;
                                nextPoint.Y += currentPoint.Y;
                                path.AddLine(currentPoint, nextPoint);
                                currentPoint = nextPoint;
                            }
                            continue;
                        }
                        if (val[i] == "M")
                        {
                            i++;
                            currentPoint = StringToPoint(val[i]);
                            while (i < val.Length - 1)
                            {
                                if (val[i + 1].Length == 1)
                                {
                                    break;
                                }
                                i++;
                                PointF nextPoint = StringToPoint(val[i]);
                                path.AddLine(currentPoint, nextPoint);
                                currentPoint = nextPoint;
                            }
                            continue;
                        }
                        if (val[i] == "l")
                        {
                            while (i < val.Length - 1)
                            {
                                if (val[i + 1].Length == 1)
                                {
                                    break;
                                }
                                i++;
                                PointF nextPoint = StringToPoint(val[i]);
                                nextPoint.X += currentPoint.X;
                                nextPoint.Y += currentPoint.Y;
                                path.AddLine(currentPoint, nextPoint);
                                currentPoint = nextPoint;
                            }
                        }
                        if (val[i] == "L")
                        {
                            while (i < val.Length - 1)
                            {
                                if (val[i + 1].Length == 1)
                                {
                                    break;
                                }
                                i++;
                                PointF nextPoint = StringToPoint(val[i]);
                                path.AddLine(currentPoint, nextPoint);
                                currentPoint = nextPoint;
                            }
                        }
                        if (val[i] == "c")
                        {
                            while (i < val.Length - 1)
                            {
                                PointF bez1 = new PointF(currentPoint.X + StringToPoint(val[i + 1]).X, currentPoint.Y + StringToPoint(val[i + 1]).Y);
                                PointF bez2 = new PointF(currentPoint.X + StringToPoint(val[i + 2]).X, currentPoint.Y + StringToPoint(val[i + 2]).Y);
                                PointF finish = new PointF(currentPoint.X + StringToPoint(val[i + 3]).X, currentPoint.Y + StringToPoint(val[i + 3]).Y);
                                path.AddBezier(currentPoint, bez1, bez2, finish);
                                currentPoint = finish;
                                i += 3;
                                if (i < val.Length - 1)
                                {
                                    if (val[i + 1].Length == 1)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        if (val[i] == "C")
                        {
                            while (i < val.Length - 1)
                            {
                                PointF bez1 = new PointF(StringToPoint(val[i + 1]).X, StringToPoint(val[i + 1]).Y);
                                PointF bez2 = new PointF(StringToPoint(val[i + 2]).X, StringToPoint(val[i + 2]).Y);
                                PointF finish = new PointF(StringToPoint(val[i + 3]).X, StringToPoint(val[i + 3]).Y);
                                path.AddBezier(currentPoint, bez1, bez2, finish);
                                currentPoint = finish;
                                i += 3;
                                if (i < val.Length - 1)
                                {
                                    if (val[i + 1].Length == 1)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        if (val[i].ToLower() == "a")
                        {
                            i++;
                            PointF point = StringToPoint(val[i]);
                            float w = point.X * 2;
                            float h = point.Y * 2;
                            float x = currentPoint.X - w;
                            float y = currentPoint.Y - h / 2;
                            path.AddEllipse(x, y, w, h);
                        }
                        if (val[i].ToLower() == "z")
                        {
                            break;
                        }
                    }
                    path.Transform(PaintObjectList[n].GetTransformMatrix());
                    g.FillPath(style.GetBrush(), path);
                    g.DrawPath(style.GetPen(), path);
                }
                if (PaintObjectList[n].GetName() == "rect")
                {
                    float x = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("x"));
                    float y = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("y"));
                    float w = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("width"));
                    float h = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("height"));
                    SVSObjectStyle style = PaintObjectList[n].GetStyle();
                    g.Transform = PaintObjectList[n].GetTransformMatrix();
                    g.FillRectangle(style.GetBrush(), x, y, w, h);
                    g.DrawRectangle(style.GetPen(), x, y, w, h);
                    g.ResetTransform();
                }
            }
            MemoryStream ms = new MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            ms.Position = 0;
            image = new System.Windows.Media.Imaging.BitmapImage();
            image.BeginInit();
            image.StreamSource = ms;
            image.EndInit();
            byte[,] map = new byte[size.Width, size.Height];
            for (int i = 0; i < size.Width; i++)
            {
                for (int j = 0; j < size.Height; j++)
                {
                    Color color = bmp.GetPixel(i, j);

                    if (color != Color.FromArgb(255, 255, 255, 255))
                    {
                        map[i, j] |= 0x80;
                    }
                }
            }
            return map;
        }
예제 #54
0
        public static System.Windows.Media.Imaging.BitmapImage GetImage(string fileId)
        {
            if (string.IsNullOrWhiteSpace(fileId))
            {
                if (_olaf == null)
                {
                    _olaf = GetImage(Olaf);
                }

                return _olaf;
            }

            using (var db = new PetoeterDb(PetoeterDb.FileName))
            {
                var file = db.FileStorage.FindById(fileId);

                if (file == null)
                {
                    if (fileId == Olaf)
                    {
                        SaveFile(Olaf, @"olaf.png");
                    }

                    return null;
                }

                using(var reader = file.OpenRead())
                {
                    System.IO.MemoryStream mem = new System.IO.MemoryStream();
                    mem.SetLength(file.Length);

                    reader.Read(mem.GetBuffer(), 0, (int)file.Length);
                    mem.Flush();

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

                    image.BeginInit();
                    image.StreamSource = mem;
                    image.EndInit();

                    image.Freeze();

                    return image;
                }
            }
        }
예제 #55
0
파일: dynViews.cs 프로젝트: kyoisi/Dynamo
            public object Convert(object value, Type targetType,
                object parameter, CultureInfo culture)
            {
                // empty images are empty...
                if (value == null) { return null; }

                try
                {
                    var image = (System.Drawing.Image)value;
                    System.Drawing.Image readImage = null;
                    // 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("C:\\falconOut\\Falcon.bmp");

                    image.Save(memoryStream, ImageFormat.Bmp);
                    // Rewind the stream...
                    //memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                    bitmap.StreamSource = memoryStream;
                    bitmap.EndInit();
                    return bitmap;
                }
                catch (Exception ex)
                {
                    dynSettings.Controller.DynamoViewModel.Log(ex.Message);
                    dynSettings.Controller.DynamoViewModel.Log(ex.StackTrace);
                    return null;
                }
            }
예제 #56
0
 void initIcon()
 {
     System.Windows.Controls.Image img = new System.Windows.Controls.Image();
     System.Windows.Media.Imaging.BitmapImage src = new System.Windows.Media.Imaging.BitmapImage();
     src.BeginInit();
     src.UriSource = new Uri(string.Format("Empires\\{0}\\Images\\{0}.png", _iconSet), UriKind.Relative);
     src.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
     src.EndInit();
     img.Source = src;
     img.Height = 32;
     img.Width = 32;
     img.Stretch = System.Windows.Media.Stretch.None;
     img.SetValue(System.Windows.Controls.Panel.ZIndexProperty, 10);
     this._icon = img;
 }
예제 #57
0
        public System.Windows.Media.Imaging.BitmapImage GetAvatarImage(string strHash)
        {
            System.Windows.Media.Imaging.BitmapImage objImage = null;
            IsolatedStorageFile storage = null;

            #if WINDOWS_PHONE
            storage = IsolatedStorageFile.GetUserStoreForApplication();
            #else
            storage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);
            #endif

            string strFileName = string.Format("{0}/{1}", AccountFolder, strHash);
            if (storage.FileExists(strFileName) == false)
            {
                storage.Dispose();
                return null;
            }

            IsolatedStorageFileStream stream = null;
            try
            {
                stream = new IsolatedStorageFileStream(strFileName, System.IO.FileMode.Open, storage);
                objImage = new System.Windows.Media.Imaging.BitmapImage();
            #if WINDOWS_PHONE
                objImage.SetSource(stream);
            #else
                objImage.BeginInit();
                objImage.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                objImage.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.None;

                objImage.StreamSource = stream;
                objImage.EndInit();

                double nWith = objImage.Width;
                double nHeight = objImage.Height;
            #endif

            }
            catch (Exception)
            {
            }
            finally
            {
                if (stream != null)
                    stream.Close();

                storage.Dispose();
            }

            return objImage;
        }
예제 #58
0
 private System.Windows.Media.Imaging.BitmapImage Bitmap2BitmapImage(System.Drawing.Bitmap dImg)
 {
     MemoryStream ms = new MemoryStream();
     dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
     System.Windows.Media.Imaging.BitmapImage bImg = new System.Windows.Media.Imaging.BitmapImage();
     bImg.BeginInit();
     bImg.StreamSource = ms;
     bImg.EndInit();
     return bImg;
 }
예제 #59
0
        public static MediaBitmapSource LoadBitmap(string filename)
        {
            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;
        }
예제 #60
0
        public void SetType(PieceType type)
        {
            this.Type = type;

            pieceImaging = null;
            pieceImaging = new System.Windows.Media.Imaging.BitmapImage();
            Bitmap tile = this.Color == PieceColor.WHITE ? tileWhites : tileBlack;

            pieceImage = tile.Clone(new Rectangle(((int)this.Type) * 75, 0, 75, 75),
            System.Drawing.Imaging.PixelFormat.DontCare);

            byte[] data;
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            pieceImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Position = 0;
            data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);

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

            this.Source = pieceImaging;
            //stream.Close();
        }