コード例 #1
0
ファイル: Utils.cs プロジェクト: BigNerd95/SimInfo
        public static void RenderTile(int width, int height, string number, object context)
        {
            string path = string.Format("/Shared/ShellContent/{0}_{1}_{2}.jpg", width, height, number);

            WriteableBitmap bmp     = null;
            UserControl     control = null;

            ManualResetEventSlim evt = new ManualResetEventSlim(false, 50);

            var act = new Action(() =>
            {
                evt.Reset();
                control             = (width == 0x9f) ? _159_159 as UserControl : _336_336 as UserControl;
                control.DataContext = context;
                control.Measure(new Size((double)width, (double)height));
                control.UpdateLayout();
                control.Arrange(new Rect(0.0, 0.0, (double)width, (double)height));
                control.UpdateLayout();

                bmp = new WriteableBitmap(width, height);
                bmp.Render(control, null);
                bmp.Invalidate();
                evt.Set();
            });

            if (!Deployment.Current.Dispatcher.CheckAccess())
            {
                Deployment.Current.Dispatcher.BeginInvoke(act);
            }
            else
            {
                act();
            }

            evt.Wait();

            if (bmp != null)
            {
                using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, file))
                    {
                        PNGWriter.WritePNG(bmp, stream, -1);
                        //Extensions.SaveJpeg(bmp, stream, width, height, 0, 100);
                    }
                }
            }
            bmp = null;
        }
コード例 #2
0
 /// <summary>
 /// Write and PNG file out to a file stream.  Currently compression is not supported.
 /// </summary>
 /// <param name="image">The WriteableBitmap to work on.</param>
 /// <param name="stream">The destination file stream.</param>
 /// <param name="compression">Level of compression to use (-1=auto, 0=none, 1-100 is percentage).</param>
 public static void WritePNG(this WriteableBitmap image, System.IO.Stream stream, int compression)
 {
     PNGWriter.DetectWBByteOrder();
     PNGWriter.WritePNG(image, stream, compression);
 }