本文整理汇总了C#中System.Windows.Media.Imaging.CroppedBitmap.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# CroppedBitmap.BeginInit方法的具体用法?C# CroppedBitmap.BeginInit怎么用?C# CroppedBitmap.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.CroppedBitmap
的用法示例。
在下文中一共展示了CroppedBitmap.BeginInit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBitMap
public CroppedBitmap GetBitMap(int id)
{
var p = GetPosition(id);
var bitmap = new CroppedBitmap();
bitmap.BeginInit();
bitmap.Source = _imageSource;
bitmap.SourceRect = new Int32Rect(p.X * _cropSize, p.Y * _cropSize, _cropSize, _cropSize);
bitmap.EndInit();
return bitmap;
}
示例2: Convert
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
CroppedBitmap cb = new CroppedBitmap();
cb.BeginInit();
cb.Source = (BitmapSource)value;
cb.SourceRect = new Int32Rect(int.Parse(parameter.ToString()), 0, 256, 256);
cb.EndInit();
return new ImageBrush((ImageSource)cb);
//return (ImageSource)cb;
}
示例3: FinalizeCreation
//.........这里部分代码省略.........
else
{
Debug.Assert(decoder.SyncObject != null);
}
}
else
{
// We already had a decoder, meaning we were downloading
Debug.Assert(!_decoder.IsDownloading);
decoder = _decoder;
_decoder = null;
}
if (decoder.Frames.Count == 0)
{
throw new System.ArgumentException(SR.Get(SRID.Image_NoDecodeFrames));
}
BitmapFrame frame = decoder.Frames[0];
BitmapSource source = frame;
Int32Rect sourceRect = SourceRect;
if (sourceRect.X == 0 && sourceRect.Y == 0 &&
sourceRect.Width == source.PixelWidth &&
sourceRect.Height == source.PixelHeight)
{
sourceRect = Int32Rect.Empty;
}
if (!sourceRect.IsEmpty)
{
CroppedBitmap croppedSource = new CroppedBitmap();
croppedSource.BeginInit();
croppedSource.Source = source;
croppedSource.SourceRect = sourceRect;
croppedSource.EndInit();
source = croppedSource;
if (_isDownloading)
{
// Unregister the download events because this is a dummy image. See comment below.
source.UnregisterDownloadEventSource();
}
}
int finalWidth = DecodePixelWidth;
int finalHeight = DecodePixelHeight;
if (finalWidth == 0 && finalHeight == 0)
{
finalWidth = source.PixelWidth;
finalHeight = source.PixelHeight;
}
else if (finalWidth == 0)
{
finalWidth = (source.PixelWidth * finalHeight) / source.PixelHeight;
}
else if (finalHeight == 0)
{
finalHeight = (source.PixelHeight * finalWidth) / source.PixelWidth;
}
if (finalWidth != source.PixelWidth || finalHeight != source.PixelHeight ||
Rotation != Rotation.Rotate0)
{
示例4: GetSpriteSources
protected CroppedBitmap[] GetSpriteSources(String source, Int32 rows, Int32 columns)
{
var sourceImage = ImageUtility.InitializeBitmapSourceFromLocation(source);
var sourceWidth = sourceImage.PixelWidth / columns;
var sourceHeight = sourceImage.PixelHeight / rows;
var sources = new CroppedBitmap[rows * columns];
for (Int32 index = 0; index < sources.Count(); index++)
{
var xPosition = (index % columns) * sourceWidth;
var yPosition = (index / columns) * sourceHeight;
var croppedBitmap = new CroppedBitmap();
croppedBitmap.BeginInit();
croppedBitmap.Source = sourceImage;
croppedBitmap.SourceRect = new Int32Rect(xPosition, yPosition, sourceWidth, sourceHeight);
croppedBitmap.EndInit();
sources[index] = croppedBitmap;
}
return sources;
}
示例5: 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;
}
}
示例6: GetCell
/// <summary>
/// Get one cell from sprite sheet
/// </summary>
/// <param name="sSpriteSheet">Filename of sprite sheet</param>
/// <returns>Cropped image as a new CroppedBitmap</returns>
public CroppedBitmap GetCell(string sSpriteSheet,int iStartX,int iStartY,int iEndX,int iEndY)
{
Image iWhichSpriteSheet;
dSpriteSheets.TryGetValue(sSpriteSheet, out iWhichSpriteSheet);
CroppedBitmap cbNew = new CroppedBitmap();
cbNew.BeginInit();
cbNew.Source = (BitmapSource)iWhichSpriteSheet.Source;
cbNew.SourceRect = new Int32Rect(iStartX,iStartY,iEndX,iEndY);
cbNew.EndInit();
return cbNew;
}
示例7: UpdateCornerImage
private static void UpdateCornerImage(Image image, Grid imageHolder, BitmapSource bitmap, RegionChooser regionChooser, bool isRetry = false)
{
// Image dimensions
int imageWidth = bitmap.PixelWidth;
int imageHeight = bitmap.PixelHeight;
double availableWidth = imageHolder.ActualWidth;
double availableHeight = imageHolder.ActualHeight;
if (availableWidth == 0 || availableHeight == 0)
{
// Intermittent bug causing this. In this case we queue it up to go again after a layout pass has been done.
if (!isRetry)
{
DispatchService.BeginInvoke(() =>
{
UpdateCornerImage(image, imageHolder, bitmap, regionChooser, isRetry: true);
});
}
return;
}
int cornerWidthPixels = (int)(availableWidth / ZoomedPixelSize);
int cornerHeightPixels = (int)(availableHeight / ZoomedPixelSize);
// Make sure the subsection of the image is not larger than the image itself
cornerWidthPixels = Math.Min(cornerWidthPixels, imageWidth);
cornerHeightPixels = Math.Min(cornerHeightPixels, imageHeight);
double cornerWidth = cornerWidthPixels * ZoomedPixelSize;
double cornerHeight = cornerHeightPixels * ZoomedPixelSize;
var croppedBitmap = new CroppedBitmap();
croppedBitmap.BeginInit();
croppedBitmap.SourceRect = regionChooser(imageWidth, imageHeight, cornerWidthPixels, cornerHeightPixels);
croppedBitmap.Source = bitmap;
croppedBitmap.EndInit();
image.Source = croppedBitmap;
image.Width = cornerWidth;
image.Height = cornerHeight;
}