/// <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); }
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; } }
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; }
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); } }
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; }
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; }
public void LoadFromUrl(Uri url) { var bitmap = new System.Windows.Media.Imaging.BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = url; bitmap.EndInit(); InnerImage.Source = bitmap; }
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; }
// 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; } }
public void Display(String path) { try { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(path)); } catch { } }
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 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); } }
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); }
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); }
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); }
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); }
/// <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); }
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)); } }
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); }
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); }
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); } } } }
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; } }
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); }
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); }
/// <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); }
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); } }
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)); }
/// <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); }
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)); } }
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); }
/// <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); }
/// <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; } }
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); }
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); }
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提醒您"; }
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)); } }
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; }
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); } } }
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); } }
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; } }
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; }
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; }
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; } } }
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); } }
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; }
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 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); }