/// <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);
        }
Exemplo n.º 2
0
        public void GetTelephoneOperator(Image img, string errorMessage)
        {
            System.Windows.Media.Imaging.BitmapImage bitmapImg = new System.Windows.Media.Imaging.BitmapImage();
            bitmapImg.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.BackgroundCreation;

            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("command", "getMobilePhoneProviderCode");
            parameters.Add("session_key", GlobalVariables.sessionId);
            parameters.Add("phone", text);

            var proxy = new WindowsPhonePostClient.PostClient(parameters);
            proxy.DownloadStringCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    JsonParse deserializedProduct = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonParse>(e.Result);
                    if (deserializedProduct.result == "success")
                    {
                        bitmapImg.UriSource = new Uri("https://www.myth.kz/VAADIN/themes/mytheme/images/" + deserializedProduct.data.providerCode + ".png", UriKind.Absolute);
                    }
                    else
                    {
                        bitmapImg.UriSource = new Uri("/img/registration/False.png", UriKind.Relative);
                        MessageBox.Show(errorMessage);
                    }
                }
                img.Source = bitmapImg;
            };
            proxy.DownloadStringAsync(new Uri("http://192.168.1.71:8080/MobileApplication/mythapi", UriKind.Absolute));
        }
        // Called when an existing photo is chosen with the photo chooser.
        private void OnPhotoChooserTaskCompleted(object sender, PhotoResult e)
        {
            // Hide text messages
            txtError.Visibility = Visibility.Collapsed;
            txtMessage.Visibility = Visibility.Collapsed;

            // Make sure the PhotoChooserTask is resurning OK
            if (e.TaskResult == TaskResult.OK)
            {
                // initialize the result photo stream
                photoStream = new MemoryStream();

                // Save the stream result (copying the resulting stream)
                e.ChosenPhoto.CopyTo(photoStream);

                // save the original file name
                fileName = e.OriginalFileName;

                // display the chosen picture
                var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                bitmapImage.SetSource(photoStream);
                imgSelectedImage.Source = bitmapImage;

                // enable the upload button
                btnUpload.IsEnabled = true;
            }
            else
            {
                // if result is not ok, make sure user can't upload
                btnUpload.IsEnabled = false;
            }
        }
Exemplo n.º 4
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;
		}
Exemplo n.º 5
0
        void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            try
            {
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                Dispatcher.BeginInvoke(() =>
                {
                    try
                    {
                        bmp.SetSource(e.Result);
                        imgCCTV.Source = bmp;

                    }
                    catch
                    {

                    }
                    finally
                    {
                        if (!ISExit)
                            BeginReadCCTV();
                    }
                }
                );

            }
            catch
            { ;}
        }
 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);
     }
 }
Exemplo n.º 7
0
 private void imageContent_ImageFailed(object sender, ExceptionRoutedEventArgs e)
 {
     var img = sender as Image;
     img.Opacity = 1;
     System.Windows.Media.Imaging.BitmapImage bm = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"/Assets/Images/NoImage.png", UriKind.RelativeOrAbsolute));
     imageContent.Source = bm;
 }
 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;
 }
Exemplo n.º 9
0
        void cameraTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult != TaskResult.OK) return;

            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);
            photoImage.Source = bmp;
        }
Exemplo n.º 10
0
		public void LoadFromUrl(Uri url)
		{
			var bitmap = new System.Windows.Media.Imaging.BitmapImage();
			bitmap.BeginInit();
			bitmap.UriSource = url;
			bitmap.EndInit();

			InnerImage.Source = bitmap;
		}
Exemplo n.º 11
0
		public void LoadFromStream(Stream stream)
		{
			var bitmap = new System.Windows.Media.Imaging.BitmapImage();
			bitmap.BeginInit();
			bitmap.StreamSource = stream;
			bitmap.EndInit();

			InnerImage.Source = bitmap;
		}
Exemplo n.º 12
0
        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;
        }
Exemplo n.º 13
0
        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    
        void CaptureTaskComplete(object sender, PhotoResult e)
        { 
            if (e.TaskResult == TaskResult.OK)
            {
                //Code to display the photo on the page in an image control named CurrentImage
                System.Windows.Media.Imaging.BitmapImage lBmp = new System.Windows.Media.Imaging.BitmapImage();
                lBmp.SetSource(e.ChosenPhoto);
                uImageHolder.Source = lBmp;
            }
        }
Exemplo n.º 14
0
 public void Display(String path)
 {
     try
     {
         Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(path));
     }
     catch
     {
     }
 }
Exemplo n.º 15
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;
        }
Exemplo n.º 16
0
        public CloseElement()
        {
            InitializeComponent();

            _fouceImg = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Silverlight.ProcessEditor;component/Images/closeFocus.png", UriKind.Relative));
            _subImg = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Silverlight.ProcessEditor;component/Images/close.png", UriKind.Relative));

            //this.Loaded += new RoutedEventHandler(CloseElement_Loaded);
           
            this.Visibility = System.Windows.Visibility.Collapsed;
        }
 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 static System.Windows.Media.Imaging.BitmapImage Bitmap2BitmapImage(this Bitmap bitmap)
 {
     using (MemoryStream ms = new MemoryStream()) {
         bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
         ms.Position = 0;
         System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
         bi.BeginInit();
         bi.StreamSource = ms;
         bi.EndInit();
         return(bi);
     }
 }
Exemplo n.º 19
0
        private BitmapImage GetMonsterIcon(string MonsterEm)
        {
            if (!System.IO.File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"HunterPie.Resources\Monsters\Icons\{MonsterEm}.png")))
            {
                return(null);
            }
            Uri         ImageURI = new Uri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"HunterPie.Resources\Monsters\Icons\{MonsterEm}.png"), UriKind.Absolute);
            BitmapImage mIcon    = new BitmapImage(ImageURI);

            mIcon.Freeze();
            return(mIcon);
        }
Exemplo n.º 20
0
        public static System.Windows.Media.Imaging.BitmapSource BitmapToBitmapSource(System.Drawing.Bitmap bmp, System.IO.MemoryStream ms)
        {
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] bytes = ms.GetBuffer();

            // Init bitmap
            System.Windows.Media.Imaging.BitmapImage bitmap = new System.Windows.Media.Imaging.BitmapImage();
            bitmap.BeginInit();
            bitmap.StreamSource = new System.IO.MemoryStream(bytes);
            bitmap.EndInit();
            return(bitmap);
        }
Exemplo n.º 21
0
        public static System.Windows.Media.ImageSource BytesToImage(byte[] bytes)
        {
            System.Windows.Media.Imaging.BitmapImage biImg = new System.Windows.Media.Imaging.BitmapImage();
            System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
            biImg.BeginInit();
            biImg.StreamSource = ms;
            biImg.EndInit();

            System.Windows.Media.ImageSource imgSrc = biImg as System.Windows.Media.ImageSource;

            return(imgSrc);
        }
Exemplo n.º 22
0
        private BitmapImage GetMonsterIcon(string MonsterEm)
        {
            if (!System.IO.File.Exists($@"HunterPie.Resources\Monsters\Icons\{MonsterEm}.png"))
            {
                return(null);
            }
            Uri         ImageURI = new Uri($@"HunterPie.Resources\Monsters\Icons\{MonsterEm}.png", UriKind.Relative);
            BitmapImage mIcon    = new BitmapImage(ImageURI);

            mIcon.Freeze();
            return(mIcon);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 将图像转换为WPF中使用的BitmapImage对象
        /// </summary>
        public static System.Windows.Media.Imaging.BitmapImage 转换为WPF的BitmapImage对象(this Image img)
        {
            MemoryStream ms = new MemoryStream();

            img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            System.Windows.Media.Imaging.BitmapImage bImage = new System.Windows.Media.Imaging.BitmapImage();
            bImage.BeginInit();
            bImage.StreamSource = new MemoryStream(ms.ToArray());
            bImage.EndInit();
            ms.Dispose();
            return(bImage);
        }
Exemplo n.º 24
0
 public UserGuideWindow_ViewModel()
 {
     WindowHeight = clientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Size.Y;
     WindowWidth  = clientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Size.X;
     WindowLeft   = clientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Location.X;
     WindowTop    = clientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Location.Y;
     UserGuide    = clientObject.UserGuide;
     if (UserGuide != null && UserGuide.ImageFilePath.Count > 0)
     {
         Image = new System.Windows.Media.Imaging.BitmapImage(new Uri(Apppath + UserGuide.ImageFilePath[0], UriKind.RelativeOrAbsolute));
     }
 }
 private void _SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (e.NewSize.Width < 320)
     {
         loadico = true;
         Icon    = null;
     }
     else if (e.NewSize.Width > 320 & loadico)
     {
         Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/LPM.Windows;component/Fonts-Icons/Icon.ico", UriKind.Absolute));
     }
 }
Exemplo n.º 26
0
        public static int[][] DecodeJpegToRaw(ref byte[] image)
        {
            int[][] rawImage = null;
            try
            {
                using (MemoryStream stream = new MemoryStream(image))
                {
                    var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                    bitmapImage.SetSource(stream);

                    var bitmap = new System.Windows.Media.Imaging.WriteableBitmap(bitmapImage);
                    int width  = bitmap.PixelWidth;
                    int height = bitmap.PixelHeight;

                    rawImage = new int[width][];
                    for (int col = 0; col < width; col++)
                    {
                        rawImage[col] = new int[height];
                        for (int row = 0; row < height; row++)
                        {
                            rawImage[col][row] = bitmap.Pixels[(row * width) + col];
                        }
                    }

                    bitmap      = null;
                    bitmapImage = null;
                    GC.Collect();
                }
            }
            catch (Exception)
            {
                //- Notice!
                //On Server or Desktop plataform, call the reference function by using reflection
                //Equals made in Android plataform, because this libaries aren't portable between WP and .NET 4.0!
                Type   bitmapType = Type.GetType("Ufc.MiscNet.ImageUtilities, MiscNet, Version=1.0.0.0, Culture=neutral");
                object instance   = Activator.CreateInstance(bitmapType);
                Type[] typeParam  = new Type[1] {
                    typeof(byte[])
                };

                MethodInfo method = bitmapType.GetMethod("DecodeJpegToRaw", typeParam);
                rawImage = (int[][])method.Invoke(instance, new object[1] {
                    image
                });
            }
            finally
            {
                image = null;
                GC.Collect();
            }
            return(rawImage);
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
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);
                    }
                }
            }
        }
Exemplo n.º 29
0
        void photoChooser_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                AddImageButton.Visibility = System.Windows.Visibility.Collapsed;
                ImageButton.Visibility    = System.Windows.Visibility.Visible;

                //Code to display the photo on the page in an image control named myImage.
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                myImage.Source = bmp;
            }
        }
Exemplo n.º 30
0
        private static ImageSource Convert(Image fs)
        {
            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();

            return(bImg);
        }
        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);
        }
Exemplo n.º 32
0
        public static System.Windows.Media.Imaging.BitmapImage ConvertToImage(byte[] image)
        {
            System.Windows.Media.Imaging.BitmapImage GetImage = new System.Windows.Media.Imaging.BitmapImage();
            using (var ms = new System.IO.MemoryStream(image))
            {
                GetImage.BeginInit();
                GetImage.CacheOption  = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                GetImage.StreamSource = ms;
                GetImage.EndInit();
            }

            return(GetImage);
        }
Exemplo n.º 33
0
        /// <summary>
        /// Convert Bitmap to image source.
        /// </summary>
        public static ImageSource GetImageSource(System.Drawing.Bitmap bitmap)
        {
            var bi = new System.Windows.Media.Imaging.BitmapImage();
            var ms = new MemoryStream();

            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            bi.BeginInit();
            bi.CacheOption  = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
            bi.StreamSource = ms;
            bi.EndInit();
            ms.Dispose();
            return(bi);
        }
Exemplo n.º 34
0
 public bool MoveRight()
 {
     if (index < UserGuide.ImageFilePath.Count - 1)
     {
         index++;
         Image = new System.Windows.Media.Imaging.BitmapImage(new Uri(Apppath + UserGuide.ImageFilePath[index], UriKind.RelativeOrAbsolute));
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 35
0
        public static System.Windows.Media.ImageSource BitmapSourceFromUri(Uri source)
        {
            var bitmap_image = new System.Windows.Media.Imaging.BitmapImage();

            bitmap_image.BeginInit();
            bitmap_image.UriSource     = source;
            bitmap_image.CacheOption   = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
            bitmap_image.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreImageCache;
            bitmap_image.EndInit();
            return(bitmap_image);

            throw new FileNotFoundException(string.Format(@"Argument source {0} does not identify an existing file", source.OriginalString));
        }
Exemplo n.º 36
0
        /// <summary>
        /// Convert Bytes To Image
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static ImageSource ConvertBytesToImageSource(byte[] image)
        {
            if (image != null)
            {
                var source = new System.Windows.Media.Imaging.BitmapImage();
                source.BeginInit();
                source.StreamSource = new MemoryStream(image);
                source.EndInit();
                return(source);
            }

            return(null);
        }
Exemplo n.º 37
0
        public void LoadIcon()
        {
            var imgurl = item.iconLink;

            if (imgurl == null)
            {
                imgurl = item.imageLink;
            }
            if (imgurl != null)
            {
                Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri(imgurl));
            }
        }
Exemplo n.º 38
0
        public static byte[] ConvertToByteArr(System.Windows.Media.Imaging.BitmapImage image)
        {
            byte[] data;
            System.Windows.Media.Imaging.JpegBitmapEncoder encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder();
            encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(image));
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                encoder.Save(ms);
                data = ms.ToArray();
            }

            return(data);
        }
Exemplo n.º 39
0
        /// <summary>Loads an image from the specified URI.</summary>
        /// <param name="path">Path of the image.</param>
        /// <returns>BitmapImage object.</returns>
        public static System.Windows.Media.Imaging.BitmapImage LoadImage(string path)
        {
            ServicePointManager.ServerCertificateValidationCallback = ThetisCore.Lib.EasyTrustPolicy.CheckValidationResult;
            System.Windows.Media.Imaging.BitmapImage bmpImg = new System.Windows.Media.Imaging.BitmapImage();
            bmpImg.BeginInit();

            // Necessary to prevent from System.ArgumentException in PresentationCore.dll
            bmpImg.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreColorProfile;

            bmpImg.UriSource = new Uri(path);
            bmpImg.EndInit();
            return(bmpImg);
        }
Exemplo n.º 40
0
 /// <summary>
 /// 从参数指定字节数组加载图片
 /// </summary>
 /// <param name="bytes">要从中加载图片的自己数组</param>
 /// <returns>从参数指定字节数组中加载的图片</returns>
 public static System.Windows.Media.ImageSource LoadImageFromBytes(byte[] bytes)
 {
     if (bytes == null || bytes.Length == 0)
     {
         return(null);
     }
     System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
     System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
     bitmapImage.BeginInit();
     bitmapImage.StreamSource = ms;
     bitmapImage.EndInit();
     return(bitmapImage);
 }
        void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show(e.ChosenPhoto.Length.ToString());
                duplicate(e.ChosenPhoto);

                //Code to display the photo on the page in an image control named myImage.
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                image.Source = bmp;
            }
        }
Exemplo n.º 42
0
        public static System.Windows.Media.Imaging.BitmapImage ConvertBitmap(System.Drawing.Bitmap bitmap)
        {
            MemoryStream ms = new MemoryStream();

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

            return(image);
        }
Exemplo n.º 43
0
        public void AddBackgroundImage()
        {
            DrawingVisual drawingVisual = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            Uri imageUri = new Uri("pack://application:,,,/SmartFish;component/Resources/sea3.jpg");
            System.Windows.Media.Imaging.BitmapImage bmi =
                new System.Windows.Media.Imaging.BitmapImage( imageUri);
            Rect rect = new Rect(new Size(Config.WindowWidth, Config.WindowHeight));
            drawingContext.DrawImage( bmi, rect);
            drawingContext.Close();
            mChildren.Add(drawingVisual);
        }
Exemplo n.º 44
0
        public static System.Windows.Media.Imaging.BitmapImage BitmapToBitmapSource(System.Drawing.Image resBitmap)
        {
            var ms = new System.IO.MemoryStream();

            resBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            ms.Position = 0;
            var bitmap = new System.Windows.Media.Imaging.BitmapImage();

            bitmap.BeginInit();
            bitmap.StreamSource = ms;
            bitmap.EndInit();
            return(bitmap);
        }
 public LeaveWindow_ViewModel()
 {
     WindowWidth  = 590;
     WindowHeight = 470;
     if (ClientObject.PopAdvert != null)
     {
         WindowHeight = 335;
         PopImg       = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "images\\AdImage\\PopImage\\" + ClientObject.PopAdvert.PopImagePath, UriKind.RelativeOrAbsolute));
     }
     WindowLeft = ClientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Location.X + (ClientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Size.X - WindowWidth) / 2;
     WindowTop  = ClientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Location.Y + (ClientObject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Size.Y - WindowHeight) / 2;
     TiteleAd   = ClientObject.TitleAdvert != null ? ClientObject.TitleAdvert.TextContent : "Juneberry提醒您";
 }
Exemplo n.º 46
0
        private Bitmap BitmapImage2Bitmap(System.Windows.Media.Imaging.BitmapImage bitmapImage)
        {
            // BitmapImage bitmapImage = new BitmapImage(new Uri("../Images/test.png", UriKind.Relative));

            using (MemoryStream outStream = new MemoryStream())
            {
                System.Windows.Media.Imaging.BitmapEncoder enc = new System.Windows.Media.Imaging.BmpBitmapEncoder();
                enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapImage));
                enc.Save(outStream);
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);

                return(new Bitmap(bitmap));
            }
        }
Exemplo n.º 47
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;
        }
        private void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            _mmsContent = null;
            if (e.TaskResult == TaskResult.OK)
            {                
                _mmsContent = new ContentInfo();
                _mmsContent.Name = e.OriginalFileName;
                _mmsContent.Content = ToByteArray(e.ChosenPhoto);

                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                selectedImage.Source = bmp;
            }
        }
        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;
        }
Exemplo n.º 50
0
 public static void Store(string imageName, System.Windows.Media.Imaging.BitmapImage image)
 {
     lock (imageCache)
     {
         if (imageCache.ContainsKey(imageName))
         {
             imageCache[imageName] = image;
         }
         else
         {
             imageCache.Add(imageName, image);
         }
     }
 }
Exemplo n.º 51
0
 private 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);
     }
 }
Exemplo n.º 52
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;
            }
        }
Exemplo n.º 53
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;
 }
Exemplo n.º 54
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;
        }
Exemplo n.º 55
0
 static void convert(double dpi, string path, string out_path)
 {
     double scale = dpi / 96.0;
     System.Windows.Xps.Packaging.XpsDocument xpsDoc =
             new System.Windows.Xps.Packaging.XpsDocument(
                     path, System.IO.FileAccess.Read);
     if (xpsDoc == null) {
         throw new System.Exception("XpsDocumentfailed");
     }
     System.Windows.Documents.FixedDocumentSequence docSeq =
             xpsDoc.GetFixedDocumentSequence();
     if (docSeq == null) {
         throw new System.Exception("GetFixedDocumentSequence failed");
     }
     System.Windows.Documents.DocumentReferenceCollection drc = docSeq.References;
     int index = 0;
     foreach (System.Windows.Documents.DocumentReference dr in drc) {
         System.Windows.Documents.FixedDocument dp = dr.GetDocument(false);
         foreach (System.Windows.Documents.PageContent pc in dp.Pages) {
             System.Windows.Documents.FixedPage fixedPage = pc.GetPageRoot(false);
             double width = fixedPage.Width;
             double height = fixedPage.Height;
             System.Windows.Size sz = new System.Windows.Size(width, height);
             fixedPage.Measure(sz);
             fixedPage.Arrange(
                     new System.Windows.Rect(new System.Windows.Point(), sz));
             fixedPage.UpdateLayout();
             System.Windows.Media.Imaging.BitmapImage bitmap =
                     new System.Windows.Media.Imaging.BitmapImage();
             System.Windows.Media.Imaging.RenderTargetBitmap renderTarget =
                     new System.Windows.Media.Imaging.RenderTargetBitmap(
                         ceil(scale * width), ceil(scale * height), dpi, dpi,
                         System.Windows.Media.PixelFormats.Default);
             renderTarget.Render(fixedPage);
             System.Windows.Media.Imaging.BitmapEncoder encoder =
                 new System.Windows.Media.Imaging.PngBitmapEncoder();
             encoder.Frames.Add(
                     System.Windows.Media.Imaging.BitmapFrame.Create(renderTarget));
             string filename = string.Format("{0}_{1}.png", out_path, index);
             System.IO.FileStream pageOutStream = new System.IO.FileStream(
                 filename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
             encoder.Save(pageOutStream);
             pageOutStream.Close();
             System.Console.WriteLine(filename);
             ++index;
         }
     }
 }
Exemplo n.º 56
0
        private void cameraCaptureVehiclePlateTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                //Code to display the photo on the page in an image control named myImage.
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);

                //MessageBox.Show(bmp.ToString());
                Image myImgage = new Image();
                myImgage.Source = bmp;
                string str = ImageConvert.ImageConvert.convertImageToBase64(myImgage);

                imgLicensePlate.Source = ImageConvert.ImageConvert.convertBase64ToImage(str);
            }
        }
Exemplo n.º 57
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);
                    }
                }    
            }
        }
        /// <summary>
        /// Retrieves a BitmapImage object for the specified image source uri.
        /// </summary>
        /// <remarks>
        /// If the specified source uri is a relative path, the image is loaded as an embedded resource stream.
        /// </remarks>
        /// <param name="value">The value that is produced by the binding target.</param>
        /// <param name="targetType">The type to convert to.</param>
        /// <param name="parameter">Not required.</param>
        /// <param name="culture">The culture to use in the converter (unused).</param>
        /// <returns>A converted value.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Uri sourceUri;

            if (value is string)
            {
                var sourceUrl = (string)value;
                if (!Uri.TryCreate(sourceUrl, UriKind.RelativeOrAbsolute, out sourceUri))
                {
                    return value;
                }
            }
            else if (value is Uri)
            {
                sourceUri = value as Uri;
            }
            else
            {
                return value;
            }

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

            if (sourceUri.IsAbsoluteUri)
            {
                bmp.UriSource = sourceUri;
                return bmp;
            }
            else
            {
                var library = typeof(ImageSourceUriConverter).Assembly;
                var libraryName = library.GetName().Name;
                var resourceName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", libraryName, sourceUri.ToString().Replace("/", "."));

                using (var stream = library.GetManifestResourceStream(resourceName))
                {
                    if (stream != null)
                    {
                        bmp.SetSource(stream);
                        return bmp;
                    }
                }
            }

            return value;
        }
Exemplo n.º 59
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;
        }
Exemplo n.º 60
0
        public Comentariu(string text, string date, string username, string image)
        {
            InitializeComponent();

            if (image != null)
            {
                Uri uri = new Uri(image, UriKind.Relative);
                ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);
                userImage.SetValue(Image.SourceProperty, img);
            }

            dateTextBlock.Text = date;
            userNameTextBlock.Text = username;
            commentTextBlock.Text = text;
            linieCanvas.Width = 600;   //tb sa stabilesc lungimea liniei in raport cu latimea paginii, nu in pixeli
            Line L = new Line();
            Linie L1 = new Linie(1, 1, linieCanvas.Width, 1, "#FF717577", 1, linieCanvas, L);
        }