本文整理汇总了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;
}
示例2: TakePartialScreenshot
public Task<BitmapSource> TakePartialScreenshot(Int32Rect rpRect)
{
return TakeScreenshot(r =>
{
var rResult = new CroppedBitmap(r, rpRect);
rResult.Freeze();
return rResult;
});
}
示例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;
}
示例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;
}
}
示例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;
}