本文整理汇总了C#中System.Windows.Media.Imaging.TransformedBitmap.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# TransformedBitmap.BeginInit方法的具体用法?C# TransformedBitmap.BeginInit怎么用?C# TransformedBitmap.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.TransformedBitmap
的用法示例。
在下文中一共展示了TransformedBitmap.BeginInit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PageLoaded
public void PageLoaded(object sender, RoutedEventArgs args)
{
// Create Image element.
Image rotated90 = new Image();
rotated90.Width = 150;
// Create the TransformedBitmap to use as the Image source.
TransformedBitmap tb = new TransformedBitmap();
// Create the source to use as the tb source.
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"sampleImages/watermelon.jpg", UriKind.RelativeOrAbsolute);
bi.EndInit();
// Properties must be set between BeginInit and EndInit calls.
tb.BeginInit();
tb.Source = bi;
// Set image rotation.
RotateTransform transform = new RotateTransform(90);
tb.Transform = transform;
tb.EndInit();
// Set the Image source.
rotated90.Source = tb;
//Add Image to the UI
Grid.SetColumn(rotated90, 1);
Grid.SetRow(rotated90, 1);
transformedGrid.Children.Add(rotated90);
}
示例2: buttonRotate_Click
private void buttonRotate_Click(object sender, RoutedEventArgs e)
{
TransformedBitmap tb = new TransformedBitmap();
tb.BeginInit();
tb.Transform = new RotateTransform(90);
tb.Source = this.imageViewModel.LoadedBitmap;
tb.EndInit();
this.imageViewModel.LoadedBitmap = tb;
this.imageViewModel.ClearPositions();
}
示例3: ShowMyFace
public ShowMyFace()
{
Title = "Show My Face";
///******************************************************************
// 3���� ShowMyFace ����
//******************************************************************/
Uri uri = new Uri("http://www.charlespetzold.com/PetzoldTattoo.jpg");
//BitmapImage bitmap = new BitmapImage(uri);
//Image img = new Image();
//img.Source = bitmap;
//Content = img;
///******************************************************************
// p1245 BitmapImage �ڵ�
//******************************************************************/
Image rotated90 = new Image();
TransformedBitmap tb = new TransformedBitmap();
FormatConvertedBitmap fb = new FormatConvertedBitmap();
CroppedBitmap cb = new CroppedBitmap();
// Create the source to use as the tb source.
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = uri;
bi.EndInit();
//cb.BeginInit();
//cb.Source = bi;
//Int32Rect rect = new Int32Rect();
//rect.X = 220;
//rect.Y = 200;
//rect.Width = 120;
//rect.Height = 80;
//cb.SourceRect = rect;
//cb.EndInit();
fb.BeginInit();
fb.Source = bi;
fb.DestinationFormat = PixelFormats.Gray2;
fb.EndInit();
// Properties must be set between BeginInit and EndInit calls.
tb.BeginInit();
tb.Source = fb;
// Set image rotation.
tb.Transform = new RotateTransform(90);
tb.EndInit();
// Set the Image source.
rotated90.Source = tb;
Content = rotated90;
}
示例4: RotateImage
public ScannedImagesModel RotateImage( int rotate )
{
var bitmap = GetBitmapImage();
var rotated = new TransformedBitmap();
rotated.BeginInit();
rotated.Source = bitmap;
var transform = new RotateTransform( rotate );
rotated.Transform = transform;
rotated.EndInit();
// get temporary file
var filename = PathUtility.GetTempFileName();
var landscape = ( rotate == 90 || rotate == 270 ) ? !Landscape : Landscape;
SaveImage( rotated, filename );
return new ScannedImagesModel( filename, landscape );
}
示例5: handleFrameFn
private void handleFrameFn(object sender, FrameReadyEventArgs e)
{
// Int32Rect cropRect = new Int32Rect(400, 380, 300, 200);
// BitmapSource croppedImage = new CroppedBitmap(e.BitmapImage, cropRect);
// image4.Source = croppedImage;
if (_rotationAngle != 0)
{
TransformedBitmap tmpImage = new TransformedBitmap();
tmpImage.BeginInit();
tmpImage.Source = e.BitmapImage; // of type BitmapImage
RotateTransform transform = new RotateTransform(_rotationAngle);
tmpImage.Transform = transform;
tmpImage.EndInit();
_dispImage.Source = tmpImage;
}
else
{
_dispImage.Source = e.BitmapImage;
}
}
示例6: getTransformedBitmap
private TransformedBitmap getTransformedBitmap(BitmapImage bi, double angle)
{
TransformedBitmap tb = new TransformedBitmap();
tb.BeginInit();
tb.Source = bi;
tb.Transform = new RotateTransform(angle);
tb.EndInit();
return tb;
}
示例7: ResizeAndReflectExifOrientation
/// <summary>
/// Resize BitmapSource and reflect Exif orientation to BitmapSource.
/// </summary>
/// <param name="bitmapSource">Source BitmapSource</param>
/// <param name="outerSize">Target outer size</param>
/// <param name="orientation">Exif orientation</param>
/// <returns>Outcome BitmapSource</returns>
private static BitmapSource ResizeAndReflectExifOrientation(BitmapSource bitmapSource, Size outerSize, int orientation)
{
var transform = new TransformGroup();
var centerX = bitmapSource.Width / 2D;
var centerY = bitmapSource.Height / 2D;
bool isRotatedRightAngle = false;
// Reflect Exif orientation.
switch (orientation)
{
case 0: // Invalid
case 1: // Horizontal (normal)
break;
case 2: // Mirror horizontal
transform.Children.Add(new ScaleTransform(-1, 1, centerX, centerY));
break;
case 3: // Rotate 180 clockwise
transform.Children.Add(new RotateTransform(180D, centerX, centerY));
break;
case 4: // Mirror vertical
transform.Children.Add(new ScaleTransform(1, -1, centerX, centerY));
break;
case 5: // Mirror horizontal and rotate 270 clockwise
transform.Children.Add(new ScaleTransform(-1, 1, centerX, centerY));
transform.Children.Add(new RotateTransform(270D, centerX, centerY));
isRotatedRightAngle = true;
break;
case 6: // Rotate 90 clockwise
transform.Children.Add(new RotateTransform(90D, centerX, centerY));
isRotatedRightAngle = true;
break;
case 7: // Mirror horizontal and rotate 90 clockwise
transform.Children.Add(new ScaleTransform(-1, 1, centerX, centerY));
transform.Children.Add(new RotateTransform(90D, centerX, centerY));
isRotatedRightAngle = true;
break;
case 8: // Rotate 270 clockwise
transform.Children.Add(new RotateTransform(270D, centerX, centerY));
isRotatedRightAngle = true;
break;
}
// Resize.
if ((0 < bitmapSource.Width) && (0 < bitmapSource.Height)) // For just in case
{
var factor = new[]
{
(outerSize.Width / (isRotatedRightAngle ? bitmapSource.Height : bitmapSource.Width)), // Scale factor of X
(outerSize.Height / (isRotatedRightAngle ? bitmapSource.Width : bitmapSource.Height)) // Scale factor of Y
}
.Where(x => 0 < x)
.DefaultIfEmpty(1D)
.Min();
transform.Children.Add(new ScaleTransform(factor, factor, centerX, centerY));
}
var bitmapTransformed = new TransformedBitmap();
bitmapTransformed.BeginInit();
bitmapTransformed.Transform = transform;
bitmapTransformed.Source = bitmapSource;
bitmapTransformed.EndInit();
return bitmapTransformed;
}
示例8: ScaleDownRotateBitmap
/// <summary>
/// Scales down and rotates a Wpf bitmap.
/// </summary>
/// <param name="sourceWpf">Original Wpf bitmap</param>
/// <param name="scale">Uniform scaling factor</param>
/// <param name="angle">Rotation angle</param>
/// <returns>Scaled and rotated Wpf bitmap</returns>
private static BitmapSource ScaleDownRotateBitmap(BitmapSource sourceWpf, double scale, int angle)
{
if (angle % 90 != 0)
{
throw new ArgumentException("Rotation angle should be a multiple of 90 degrees.", "angle");
}
// Do not upscale and no rotation.
if ((float)scale >= 1.0f && angle == 0)
{
return sourceWpf;
}
// Set up the transformed thumbnail
TransformedBitmap thumbWpf = new TransformedBitmap();
thumbWpf.BeginInit();
thumbWpf.Source = sourceWpf;
TransformGroup transform = new TransformGroup();
// Rotation
if (Math.Abs(angle) % 360 != 0)
transform.Children.Add(new RotateTransform(Math.Abs(angle)));
// Scale
if ((float)scale < 1.0f || angle < 0) // Only downscale
{
double xScale = Math.Min(1.0, Math.Max(1.0 / (double)sourceWpf.PixelWidth, scale));
double yScale = Math.Min(1.0, Math.Max(1.0 / (double)sourceWpf.PixelHeight, scale));
if (angle < 0)
xScale = -xScale;
transform.Children.Add(new ScaleTransform(xScale, yScale));
}
// Apply the tranformation
thumbWpf.Transform = transform;
thumbWpf.EndInit();
return thumbWpf;
}
示例9: CreateTransformedBitmap
private static TransformedBitmap CreateTransformedBitmap(BitmapSource source, VCProfile profile)
{
var transformedBitmap = new TransformedBitmap();
transformedBitmap.BeginInit();
transformedBitmap.Source = source;
var transformGroup = new TransformGroup();
transformGroup.Children.Add(new ScaleTransform(profile.FlipHorizontal ? -1 : 1, profile.FlipVertical ? -1 : 1));
transformGroup.Children.Add(new RotateTransform(ConvertRotationToDegrees(profile.Rotation)));
transformedBitmap.Transform = transformGroup;
transformedBitmap.EndInit();
transformedBitmap.Freeze();
return transformedBitmap;
}
示例10: GetBitmapSource
private ImageSource GetBitmapSource(LoadImageRequest loadTask, DisplayOptions loadType)
{
DisplayOptions lt = loadType;
Image image = loadTask.Image;
string source = loadTask.Source;
string nSource = source;
string cacheFile = Path.Combine(AppStateSettings.CacheFolder, "Media", nSource.GetSHA1Hash().ToString() + "s" + loadTask.CachHeight + ".png"); // REVIEW TODO: Used Path instead of String concat.
if (File.Exists(cacheFile))
{
nSource = cacheFile;
lt = DisplayOptions.FullResolution;
//return new BitmapImage(new Uri("file://" + cacheFile));
}
ImageSource imageSource = null;
if (!string.IsNullOrWhiteSpace(nSource))
{
Stream imageStream = null;
SourceType sourceType = SourceType.LocalDisk;
image.Dispatcher.Invoke(new ThreadStart(delegate
{
sourceType = Loader.GetSourceType(image);
}));
try
{
if (loadTask.Stream == null)
{
ILoader loader = LoaderFactory.CreateLoader(sourceType, nSource);
imageStream = loader.Load(nSource);
loadTask.Stream = imageStream;
}
else
{
imageStream = new MemoryStream();
loadTask.Stream.Position = 0;
loadTask.Stream.CopyTo(imageStream);
imageStream.Position = 0;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
if (imageStream != null)
{
try
{
if (lt == DisplayOptions.Preview)
{
BitmapFrame bitmapFrame = BitmapFrame.Create(imageStream);
imageSource = bitmapFrame.Thumbnail;
if (imageSource == null) // Preview it is not embedded into the file
{
// we'll make a thumbnail image then ... (too bad as the pre-created one is FAST!)
TransformedBitmap thumbnail = new TransformedBitmap();
thumbnail.BeginInit();
thumbnail.Source = bitmapFrame as BitmapSource;
// we'll make a reasonable sized thumnbail with a height of 240
int pixelH = bitmapFrame.PixelHeight;
int pixelW = bitmapFrame.PixelWidth;
int decodeH = (int)loadTask.CachHeight;
int decodeW = (bitmapFrame.PixelWidth * decodeH) / pixelH;
double scaleX = decodeW / (double)pixelW;
double scaleY = decodeH / (double)pixelH;
TransformGroup transformGroup = new TransformGroup();
transformGroup.Children.Add(new ScaleTransform(scaleX, scaleY));
thumbnail.Transform = transformGroup;
thumbnail.EndInit();
// this will disconnect the stream from the image completely ...
WriteableBitmap writable = new WriteableBitmap(thumbnail);
BitmapFrame frame = BitmapFrame.Create(writable);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(frame);
using (var stream = File.Create(cacheFile))
{
encoder.Save(stream);
}
writable.Freeze();
imageSource = writable;
}
}
else if (lt == DisplayOptions.FullResolution)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
//.........这里部分代码省略.........
示例11: initializeProjectileImage
private Image initializeProjectileImage(Uri spriteUri, bool rotate = false)
{
Image newImage = new Image();
newImage.VerticalAlignment = System.Windows.VerticalAlignment.Top;
newImage.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
newImage.Margin = getRandomEdge();
TransformedBitmap temp = new TransformedBitmap();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = spriteUri;
bi.EndInit();
temp.BeginInit();
temp.Source = bi;
RotateTransform transform;
if (rotate)
{
transform = new RotateTransform(rand.Next(0, 3) * 90);
}
else
{
transform = new RotateTransform(0);
}
temp.Transform = transform;
temp.EndInit();
newImage.Source = temp;
return newImage;
}
示例12: Resize
private byte[] Resize(byte[] bytes, int? width, int? height, int qualityLevel)
{
if (bytes == null)
throw new Exception("Bytes parameter is null.");
var image = new BitmapImage();
image.BeginInit();
if (width.HasValue)
image.DecodePixelWidth = width.Value;
if (height.HasValue)
image.DecodePixelHeight = height.Value;
image.StreamSource = new MemoryStream(bytes);
image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
image.EndInit();
var transform = new TransformedBitmap();
transform.BeginInit();
transform.Source = image;
transform.EndInit();
return ToJpegBytes(transform, qualityLevel);
}
示例13: RotateButton_OnClick
private void RotateButton_OnClick (object sender, RoutedEventArgs e)
{
TransformedBitmap RotatedSource = new TransformedBitmap();
RotatedSource.BeginInit ();
RotatedSource.Source = Source;
RotatedSource.Transform = new RotateTransform (90);
RotatedSource.EndInit ();
Source = RotatedSource;
advancedContentPresenter.Background = new ImageBrush(Source);
advancedContentPresenter.FitToBackgroundImage ();
}
示例14: ReCreateThumbnail
//.........这里部分代码省略.........
else
{
int width = aThumbWidth;
int height = aThumbHeight;
double num3 = (double)bitmap1.Width / (double)bitmap1.Height;
if (bitmap1.Width > bitmap1.Height)
height = (int)Math.Floor((double)width / num3);
else
width = (int)Math.Floor(num3 * (double)height);
try
{
GrabUtil.FileDelete(thumbnailImageDest);
}
catch (Exception ex)
{
Log.Error("Picture: Error deleting old thumbnail - {0}", (object)ex.Message);
}
bitmap2 = new Bitmap((Image)bitmap1, width, height);
bitmap2.Save(thumbnailImageDest, Thumbs.ThumbCodecInfo, Thumbs.ThumbEncoderParams);
File.SetAttributes(thumbnailImageDest, File.GetAttributes(thumbnailImageDest) | FileAttributes.Hidden);
flag = true;
}
}
}
else
{
BitmapMetadata meta = bitmapFrame.Metadata as BitmapMetadata;
bitmapSource = bitmapFrame.Thumbnail;
if (autocreateLargeThumbs)
{
if (bitmapSource != null)
{
transformedBitmap = new TransformedBitmap();
transformedBitmap.BeginInit();
transformedBitmap.Source = (BitmapSource)bitmapFrame;
int pixelHeight = bitmapFrame.PixelHeight;
int pixelWidth = bitmapFrame.PixelWidth;
int num3 = bitmapFrame.PixelHeight * num2 / pixelWidth;
double scaleX = (double)num2 / (double)pixelWidth;
double scaleY = (double)num3 / (double)pixelHeight;
transformGroup = new TransformGroup();
transformGroup.Children.Add((Transform)new ScaleTransform(scaleX, scaleY));
transformedBitmap.Transform = (Transform)transformGroup;
transformedBitmap.EndInit();
bitmapSource = (BitmapSource)transformedBitmap;
bitmapSource = Picture.MetaOrientation(meta, bitmapSource);
flag = Picture.BitmapFromSource(bitmapSource, thumbnailImageDest);
}
}
else if (bitmapSource != null)
{
bitmapSource = Picture.MetaOrientation(meta, bitmapSource);
flag = Picture.BitmapFromSource(bitmapSource, thumbnailImageDest);
}
}
}
catch (Exception ex1)
{
try
{
try
{
using (FileStream fileStream = new FileStream(thumbnailImageSource, FileMode.Open, FileAccess.Read))
{
using (aDrawingImage = Image.FromStream((Stream)fileStream, true, false))
flag = Picture.CreateThumbnail(aDrawingImage, thumbnailImageDest, aThumbWidth, aThumbHeight, iRotate, aFastMode);
示例15: Transform
public static BitmapSource Transform(BitmapSource source, Transform transform)
{
if (source == null) throw new ArgumentNullException("source");
if (transform == null) throw new ArgumentNullException("transform");
TransformedBitmap target = new TransformedBitmap();
target.BeginInit();
target.Source = source;
target.Transform = transform;
target.EndInit();
target.Freeze();
return CloneImage(target);
}