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


C# CroppedBitmap.Freeze方法代码示例

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


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

示例1: GetImageSource

 private static ImageSource GetImageSource()
 {
     BitmapSource source = ImageHelper.BitmapSourceFromBitmap(new Bitmap(Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("Paket.VisualStudio.Resources.NuGet.ico"))));
     Int32Rect sourceRect = new Int32Rect(0, 0, 16, 16);
     ImageSource imageSource = new CroppedBitmap(source, sourceRect);
     imageSource.Freeze();
     return imageSource;
 }
开发者ID:freeman,项目名称:Paket.VisualStudio,代码行数:8,代码来源:NuGetNameCompletionListProvider.cs

示例2: TakePartialScreenshot

        public Task<BitmapSource> TakePartialScreenshot(Int32Rect rpRect)
        {
            return TakeScreenshot(r =>
            {
                var rResult = new CroppedBitmap(r, rpRect);
                rResult.Freeze();

                return rResult;
            });
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun-Fx4,代码行数:10,代码来源:ScreenshotService.cs

示例3: CropFrame

        private static WriteableBitmap CropFrame(ref Rectangle srcRect, BitmapSource source)
        {
            var x = Math.Min(srcRect.X, source.PixelWidth - 1);
            var y = Math.Min(srcRect.Y, source.PixelHeight - 1);
            x = Math.Max(x, 0);
            y = Math.Max(y, 0);

            var right = srcRect.X + srcRect.Width;
            right = Math.Min(right, source.PixelWidth);
            right = Math.Max(right, 0);

            var bottom = srcRect.Y + srcRect.Height;
            bottom = Math.Min(bottom, source.PixelHeight);
            bottom = Math.Max(bottom, 0);

            var crop = new CroppedBitmap(source, new Int32Rect(x, y, right - x, bottom - y));
            crop.Freeze();

            var bmp = BitmapFactory.ConvertToPbgra32Format(crop);
            return bmp;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:21,代码来源:SpriteBitmapCache.cs

示例4: ProvideValue

        /// <summary>
        /// When implemented in a derived class, returns an object that is provided as the value of
        /// the target property for this markup extension.
        /// </summary>
        /// <param name="serviceProvider">
        /// A service provider helper that can provide services for the markup extension.
        /// </param>
        /// <returns>
        /// The object value to set on the property where the extension is applied.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            // Setting BitmapImage.SourceRect has no effect. Need to use CroppedBitmap.
            if (WindowsHelper.IsInDesignMode)
            {
                // ----- Design time:
                // Design mode requires special code when used inside a WPF styles.
                var bitmapImage = Source as BitmapImage;
                if (bitmapImage == null)
                    return null;

                var croppedBitmap = new CroppedBitmap();
                croppedBitmap.BeginInit();
                croppedBitmap.Source = new BitmapImage(bitmapImage.UriSource);
                croppedBitmap.SourceRect = SourceRect;
                croppedBitmap.EndInit();
                croppedBitmap.Freeze();

                return croppedBitmap;
            }
            else
            {
                // ----- Run time:
                var bitmapSource = Source as BitmapSource;
                if (bitmapSource == null)
                    return null;

                // Freeze bitmap for performance.
                bitmapSource.Freeze();

                var croppedBitmap = new CroppedBitmap(bitmapSource, SourceRect);
                croppedBitmap.Freeze();

                return croppedBitmap;
            }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:46,代码来源:PackedBitmapExtension.cs

示例5: Convert

        // expects the target object as the first parameter, and the resource key as the second
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Length < 2)
            {
                return null;
            }

            var element = values[0] as FrameworkElement;
            var resourceKey = values[1];

            if (element == null || resourceKey == null)
            {
                return null;
            }

            if (ResourceKeyFormat != null)
            {
                resourceKey = string.Format(ResourceKeyFormat, resourceKey);
            }

            if (ResourceKeyConverter != null)
            {
                resourceKey = ResourceKeyConverter.Convert(resourceKey, targetType, ConverterParameter, culture);
            }

            if (resourceKey == null) return null;

            var resource = element.TryFindResource(resourceKey);

            if (resource != null)
            {
                if (CropRect == null) return resource;
                else if (resource is BitmapSource)
                {
                    BitmapSource bitmap = resource as BitmapSource;
                    var result = new CroppedBitmap(bitmap, CropRect);
                    result.Freeze();
                    return result;
                }
            }

            string fileName = null;
            resourceKey = values[1];

            if (StringFormat != null)
            {
                fileName = string.Format(StringFormat, resourceKey);
            }

            if (ResourceKeyConverter != null)
            {
                fileName = ResourceKeyConverter.Convert(fileName, targetType, ConverterParameter, culture).ToString();
            }

            if (fileName != null)
            {

                fileName = string.Format("pack://siteoforigin:,,,/{0}", fileName);

                try
                {
                    object imageObj = (new ImageSourceConverter()).ConvertFromString(fileName);
                    var image = imageObj as ImageSource;
                    if (image != null)
                    {
                        if (CropRect == null) return image;
                        else if (image is BitmapSource)
                        {
                            BitmapSource bitmap = image as BitmapSource;
                            var result = new CroppedBitmap(bitmap, CropRect);
                            result.Freeze();
                            return result;
                        }
                    }
                }
                catch (NullReferenceException)
                {
                }
                catch (NotSupportedException)
                {
                }
                catch (ArgumentException)
                {
                    Trace.TraceWarning("Image not in expected size: {0}", fileName);
                }
            }

            Trace.TraceWarning("Resource not found: {0} or {1}\n", resourceKey, fileName);
            return null;
        }
开发者ID:RagingBigFemaleBird,项目名称:sgs,代码行数:91,代码来源:FileNameToImageSourceConverter.cs


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