当前位置: 首页>>代码示例>>C#>>正文


C# ImageState.WpfDestinationImageSettings方法代码示例

本文整理汇总了C#中ImageResizer.Resizing.ImageState.WpfDestinationImageSettings方法的典型用法代码示例。如果您正苦于以下问题:C# ImageState.WpfDestinationImageSettings方法的具体用法?C# ImageState.WpfDestinationImageSettings怎么用?C# ImageState.WpfDestinationImageSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageResizer.Resizing.ImageState的用法示例。


在下文中一共展示了ImageState.WpfDestinationImageSettings方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildJob

        protected override RequestedAction BuildJob(ImageJob job)
        {
            if (!"wpf".Equals(job.Settings["builder"])) return RequestedAction.None;

            // Estrazione delle ResizeSettings
            ResizeSettings settings = job.Settings;

            Stream s = null;
            bool disposeStream = !(job.Source is Stream);
            long originalPosition = 0;
            bool restoreStreamPosition = false;

            string path;
            s = c.CurrentImageBuilder.GetStreamFromSource(job.Source, job.Settings, ref disposeStream, out path, out restoreStreamPosition);
            if (s == null) return RequestedAction.None; //We don't support the source object!
            if (job.ResetSourceStream) restoreStreamPosition = true;
            job.SourcePathData = path;

            // Instanzio uno stream locale per le operazioni WPF
            using (MemoryStream localStream = (s is MemoryStream) ? (MemoryStream)s : StreamExtensions.CopyToMemoryStream(s))
            {
                if (s != null && restoreStreamPosition && s.CanSeek)
                    s.Seek(originalPosition, SeekOrigin.Begin);

                if (disposeStream)
                    s.Dispose();

                /* ? ? ? */
                IEncoder managedEncoder = c.Plugins.GetEncoder(job.Settings, job.SourcePathData);
                bool supportsTransparency = managedEncoder.SupportsTransparency;

                // Recupero le dimensioni originali
                var frame = BitmapFrame.Create(StreamExtensions.CopyToMemoryStream(localStream));
                System.Windows.Size originalSize = new System.Windows.Size(frame.PixelWidth, frame.PixelHeight);

                // Resetto lo stream locale alla posizione iniziale, dopo aver letto i metadata
                localStream.Position = 0;

                // Uhm... sono costretto a referenziare le System.Drawing (GDI) per questo,
                // TODO: chiedere al tipo se si può prevedere un costruttore di ImageState che non preveda un System.Drawing.Size come parametro
                System.Drawing.Size orig = new System.Drawing.Size((int)originalSize.Width, (int)originalSize.Height);

                using (ImageState imageState = new ImageState(settings, orig, true))
                {
                    c.CurrentImageBuilder.Process(imageState);

                    Rectangle imageDest = PolygonMath.ToRectangle(PolygonMath.GetBoundingBox(imageState.layout["image"]));

                    BitmapSource finalImage;

                    BitmapImage bi = new BitmapImage();
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.BeginInit();
                    bi.StreamSource = localStream;

                    WpfImageSettings wpfImageSettings = imageState.WpfDestinationImageSettings(settings);

                    bi.DecodePixelWidth = Convert.ToInt32(wpfImageSettings.DestinationImageWidth);
                    bi.DecodePixelHeight = Convert.ToInt32(wpfImageSettings.DestinationImageHeight);
                    bi.EndInit();

                    // Creation of the encoder
                    WpfEncoderPlugin wpfEncoder = new WpfEncoderPlugin(settings, job.SourcePathData);

                    RenderTargetBitmap final = new RenderTargetBitmap(imageState.finalSize.Width, imageState.finalSize.Height, settings.Get<int>("dpi", 96), settings.Get<int>("dpi", 96), PixelFormats.Default);
                    DrawingVisual dv = new DrawingVisual();

                    using (DrawingContext dc = dv.RenderOpen())
                    {
                        string ARGBBackgroundColor = String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", wpfEncoder.MimeType.Equals("image/jpeg") ? 255 : settings.BackgroundColor.A,
                                                                                                settings.BackgroundColor.R,
                                                                                                settings.BackgroundColor.G,
                                                                                                settings.BackgroundColor.B);

                        System.Windows.Media.Brush BrushBackgroundColor = new System.Windows.Media.SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(ARGBBackgroundColor));

                        /* todo: verificare */
                        dc.DrawRectangle(BrushBackgroundColor, null, new Rect(0, 0, wpfImageSettings.DestinationImageWidth, wpfImageSettings.DestinationImageHeight));

                        Rect rect = new Rect(wpfImageSettings.OffsetX, wpfImageSettings.OffsetY, wpfImageSettings.DestinationImageWidth, wpfImageSettings.DestinationImageHeight);

                        //dc.PushTransform(new RotateTransform(settings.Rotate, (double)imageState.finalSize.Width / 2, (double)imageState.finalSize.Height / 2));

                        dc.DrawImage(bi, rect);
                    }

                    final.Render(dv);
                    finalImage = final;

                    // Write the image to the output stream
                    wpfEncoder.Write(finalImage, (Stream)job.Dest);
                }
            }

            return RequestedAction.None;
        }
开发者ID:eakova,项目名称:resizer,代码行数:96,代码来源:WpfBuilder.cs


注:本文中的ImageResizer.Resizing.ImageState.WpfDestinationImageSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。