protected internal static BitmapSource GetBitmapSource(StockIconIdentifier identifier, StockIconOptions flags)
        {
            BitmapSource bitmapSource = (BitmapSource)InteropHelper.MakeImage(identifier, StockIconOptions.Handle | flags);

            bitmapSource.Freeze();
            return(bitmapSource);
        }
Beispiel #2
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <returns>An <see cref="Object"/> that represents the converted value.</returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            Bitmap bitmap = value as Bitmap;

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

            IntPtr bmpPt = bitmap.GetHbitmap();

            // create the bitmapSource
            System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                bmpPt,
                IntPtr.Zero,
                Int32Rect.Empty,
                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

            // freeze the bitmap to avoid hooking events to the bitmap
            bitmapSource.Freeze();

            // free memory
            DeleteObject(bmpPt);

            // return bitmapSource
            return(bitmapSource);
        }
 public VideoFrame(BitmapSource snapshot, TimeSpan mediaTime)
 {
     Snapshot = snapshot;
     MediaTime = mediaTime;
     snapshot.Freeze();
 }
Beispiel #4
0
        /// <summary>
        /// Updates the bitmap and the dimensions calculation.
        /// </summary>
        /// <param name="bmp">The bitmap to use to calculate guidelines.</param>
        private void UpdateScreenshot(Bitmap bmp)
        {
            if (bmp != null)
            {
                lock (_bitmapLock)
                {
                    IntPtr hbitmap = IntPtr.Zero;

                    try
                    {
                        ScreenshotBitmap = bmp;
                        hbitmap = bmp.GetHbitmap();

                        ScreenshotImage = Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        if (ScreenshotImage != null) { ScreenshotImage.Freeze(); }
                        UpdateGuidelines();
                    }
                    catch (Exception e)
                    {
            #if DEBUG
                        System.Diagnostics.Debug.WriteLine(e);
            #endif
                    }
                    finally
                    {
                        if (hbitmap != IntPtr.Zero) { Win32API.DeleteObject(hbitmap); }
                        GC.Collect();
                    }
                }

            }
        }
 static UserProfileControl()
 {
     _Fallback = new BitmapImage(new Uri("pack://application:,,,/Inbox2.UI.Resources;component/icons/inbox-icon.png"));
     _Fallback.Freeze();
 }
 static UnifiedModelSystemInterface()
 {
     try
     {
         try
         {
             ModuleIcon = CreateBitmapCache("pack://application:,,,/XTMF.Gui;component/Resources/Settings.png");
             ModuleIcon.Freeze();
             ListIcon = CreateBitmapCache("pack://application:,,,/XTMF.Gui;component/Resources/Plus.png");
             ListIcon.Freeze();
         }
         catch
         {
         }
         HighlightColour = (Color)Application.Current.TryFindResource("SelectionBlue");
         FocusColour = (Color)Application.Current.TryFindResource("FocusColour");
         ControlBackgroundColour = (Color)Application.Current.TryFindResource("ControlBackgroundColour");
         AddingYellow = (Color)Application.Current.TryFindResource("AddingYellow");
         InformationGreen = (Color)Application.Current.TryFindResource("InformationGreen");
         WarningRed = (Color)Application.Current.TryFindResource("WarningRed");
     }
     catch
     {
     }
 }
		/// <summary>Constructs successul rendering result</summary>
		/// <param name="request">Source request</param>
		/// <param name="result">Rendered bitmap</param>
		public RenderResult(RenderRequest request, BitmapSource result)
		{
            this.bitmap = result;
			this.request = request;
            result.Freeze();
		}
 public static void InsertSource(string imagePath, BitmapSource source)
 {
     ClearCache(imagePath);
     source.Freeze();
     images[imagePath] = source;
 }
 static NoteIconConverter()
 {
     _Fallback = new BitmapImage(new Uri("pack://application:,,,/Inbox2.UI.Resources;component/icons/icon_forlater.png"));
     _Fallback.Freeze();
 }
Beispiel #10
0
 private BitmapSource GetBitmapSource()
 {
     IntPtr inptr = _bitmap.GetHbitmap();
     _bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
         inptr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
     DeleteObject(inptr);
     if (!_bitmapSource.IsFrozen && _bitmapSource.CanFreeze)
         _bitmapSource.Freeze();
     return _bitmapSource;
 }
Beispiel #11
0
 private static BitmapSource MetaOrientation(BitmapMetadata meta, BitmapSource ret)
 {
     double angle = 0.0;
       if (meta != null && ret != null)
       {
     if (meta.GetQuery("/app1/ifd/{ushort=274}") != null)
       Picture.orientation = (Picture.ExifOrientations)Enum.Parse(typeof(Picture.ExifOrientations), meta.GetQuery("/app1/ifd/{ushort=274}").ToString());
     switch (Picture.orientation)
     {
       case Picture.ExifOrientations.Rotate180:
     angle = 180.0;
     break;
       case Picture.ExifOrientations.Rotate270:
     angle = 90.0;
     break;
       case Picture.ExifOrientations.Rotate90:
     angle = -90.0;
     break;
     }
     if (angle != 0.0)
     {
       ret = (BitmapSource)new TransformedBitmap(ret.Clone(), (Transform)new RotateTransform(angle));
       ret.Freeze();
     }
       }
       return ret;
 }
Beispiel #12
0
        /// <summary>
        ///     Post a message and image (from the webcam), Posts are made to @nzokdat
        /// </summary>
        /// <param name="message"></param>
        /// <param name="bitsource"></param>
        /// <param name="depO"></param>
        public void postTweet(String message, BitmapSource bitsource, DependencyObject depO)
        {
            try
            {
                (Window.GetWindow(depO) as TopWindow).StopTimer();
                //twitter service
                bitsource.Freeze();
                var frame = BitmapFrame.Create(bitsource);
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(frame);
                byte[] data;

                using (MemoryStream ms = new MemoryStream())
                {
                    encoder.Save(ms);
                    data = ms.ToArray();
                }

                Stream stream = new MemoryStream(data);
                List<Object> args = new List<Object>();
                args.Add(message);

                args.Add(bitsource);
                args.Add(stream);
                timer = depO;

                worker.DoWork += m_oWorker_DoWork;
                worker.RunWorkerAsync(args);
            }
            catch (Exception)
            {
                (Window.GetWindow(depO) as TopWindow).StartTimer();
            }
        }
 private BitmapSource Freeze(BitmapSource apply)
 {
     apply.Freeze();
     return apply;
 }