本文整理汇总了C#中System.Windows.Media.Imaging.CroppedBitmap类的典型用法代码示例。如果您正苦于以下问题:C# CroppedBitmap类的具体用法?C# CroppedBitmap怎么用?C# CroppedBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CroppedBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了CroppedBitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PageLoaded
public void PageLoaded(object sender, RoutedEventArgs args)
{
// Create an Image element.
Image croppedImage = new Image();
croppedImage.Width = 200;
croppedImage.Margin = new Thickness(5);
// Create a CroppedBitmap based off of a xaml defined resource.
CroppedBitmap cb = new CroppedBitmap(
(BitmapSource)this.Resources["masterImage"],
new Int32Rect(30, 20, 105, 50)); //select region rect
croppedImage.Source = cb; //set image source to cropped
// Add Image to the UI
Grid.SetColumn(croppedImage, 1);
Grid.SetRow(croppedImage, 1);
croppedGrid.Children.Add(croppedImage);
// Create an Image element.
Image chainImage = new Image();
chainImage.Width = 200;
chainImage.Margin = new Thickness(5);
// Create the cropped image based on previous CroppedBitmap.
CroppedBitmap chained = new CroppedBitmap(cb,
new Int32Rect(30, 0, (int)cb.Width-30, (int)cb.Height));
// Set the image's source.
chainImage.Source = chained;
// Add Image to the UI.
Grid.SetColumn(chainImage, 1);
Grid.SetRow(chainImage, 3);
croppedGrid.Children.Add(chainImage);
}
示例2: Pieza
public Pieza(int valor, int fila, int columna, CroppedBitmap imagen)
{
Valor = valor;
Fila = fila;
Columna = columna;
Imagen = imagen;
}
示例3: RenderPages
/// <summary>
/// Generates an image of each page in the year book
/// and saves it to the src folder
/// </summary>
/// <param name="bv"></param>
/// <param name="folderloc"></param>
private static void RenderPages(BookViewer bv, string folderloc)
{
int currentpage = bv.ViewIndex;
//loops though each page
foreach (Page p in bv.CurrentBook.Pages)
{
bv.ViewIndex = p.PageNumber;
//forces the canvas to re-render
BookViewer.DesignerCanvas.UpdateLayout();
//takes a picture of the canvas
RenderTargetBitmap rtb = new RenderTargetBitmap(PaperSize.Pixel.PaperWidth, PaperSize.Pixel.PaperHeight, 96, 96, PixelFormats.Default);
rtb.Render(BookViewer.DesignerCanvas);
//getting the bleed margin
Int32Rect bleedmargin = new Int32Rect((PaperSize.Pixel.PaperWidth - PaperSize.Pixel.BleedWidth) / 2, (PaperSize.Pixel.PaperHeight - PaperSize.Pixel.BleedHeight) / 2, PaperSize.Pixel.BleedWidth, PaperSize.Pixel.BleedHeight);
//cropping the image
CroppedBitmap cb = new CroppedBitmap(rtb, bleedmargin);
//encodes the image in png format
PngBitmapEncoder pbe = new PngBitmapEncoder();
pbe.Frames.Add(BitmapFrame.Create(cb));
//saves the resulting image
FileStream fs = File.Open(folderloc + "\\src\\" + (p.PageNumber+1) + ".png", FileMode.Create);
pbe.Save(fs);
fs.Flush();
fs.Close();
}
bv.ViewIndex = currentpage;
}
示例4: GetColorFromImage
private Color GetColorFromImage(Point p)
{
try
{
var bounds = VisualTreeHelper.GetDescendantBounds(this);
var rtb = new RenderTargetBitmap((int) bounds.Width, (int) bounds.Height, 96, 96, PixelFormats.Default);
rtb.Render(this);
byte[] arr;
var png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtb));
using (var stream = new MemoryStream())
{
png.Save(stream);
arr = stream.ToArray();
}
BitmapSource bitmap = BitmapFrame.Create(new MemoryStream(arr));
var pixels = new byte[4];
var cb = new CroppedBitmap(bitmap, new Int32Rect((int) p.X, (int) p.Y, 1, 1));
cb.CopyPixels(pixels, 4, 0);
return Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0]);
}
catch (Exception)
{
return ColorBox.Color;
}
}
示例5: CreateScreenshot
/// <summary>Creates the screenshot of entire plotter element</summary>
/// <returns></returns>
internal static BitmapSource CreateScreenshot(UIElement uiElement, Int32Rect screenshotSource)
{
Window window = Window.GetWindow(uiElement);
if (window == null)
{
return CreateElementScreenshot(uiElement);
}
Size size = window.RenderSize;
//double dpiCoeff = 32 / SystemParameters.CursorWidth;
//int dpi = (int)(dpiCoeff * 96);
double dpiCoeff = 1;
int dpi = 96;
RenderTargetBitmap bmp = new RenderTargetBitmap(
(int)(size.Width * dpiCoeff), (int)(size.Height * dpiCoeff),
dpi, dpi, PixelFormats.Default);
// white background
Rectangle whiteRect = new Rectangle { Width = size.Width, Height = size.Height, Fill = Brushes.White };
whiteRect.Measure(size);
whiteRect.Arrange(new Rect(size));
bmp.Render(whiteRect);
// the very element
bmp.Render(uiElement);
CroppedBitmap croppedBmp = new CroppedBitmap(bmp, screenshotSource);
return croppedBmp;
}
示例6: Image_MouseMove
private void Image_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
var AssociatedObject = this;
// Retrieve the coordinate of the mouse position in relation to the supplied image.
Point point = e.GetPosition(AssociatedObject);
// Use RenderTargetBitmap to get the visual, in case the image has been transformed.
var renderTargetBitmap = new RenderTargetBitmap((int) AssociatedObject.ActualWidth,
(int) AssociatedObject.ActualHeight,
96, 96, PixelFormats.Default);
renderTargetBitmap.Render(AssociatedObject);
// Make sure that the point is within the dimensions of the image.
if ((point.X <= renderTargetBitmap.PixelWidth) && (point.Y <= renderTargetBitmap.PixelHeight))
{
// Create a cropped image at the supplied point coordinates.
var croppedBitmap = new CroppedBitmap(renderTargetBitmap,
new Int32Rect((int) point.X, (int) point.Y, 1, 1));
// Copy the sampled pixel to a byte array.
var pixels = new byte[4];
croppedBitmap.CopyPixels(pixels, 4, 0);
// Assign the sampled color to a SolidColorBrush and return as conversion.
var SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]);
TextBox.Text = "#" + SelectedColor.ToString().Substring(3);
Label.Background = new SolidColorBrush(SelectedColor);
}
}
示例7: Image_MouseDown
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
try
{
var cb = new CroppedBitmap((BitmapSource) (((Image) e.Source).Source),
new Int32Rect((int) Mouse.GetPosition(e.Source as Image).X,
(int) Mouse.GetPosition(e.Source as Image).Y, 1, 1));
_pixels = new byte[4];
try
{
cb.CopyPixels(_pixels, 4, 0);
SetColor(Color.FromRgb(_pixels[2], _pixels[1], _pixels[0]));
UpdateMarkerPosition();
if (OnColorSelected != null)
OnColorSelected(SelectedColor);
}
catch
{
// not logged
}
UpdateSlider();
}
catch (Exception)
{
// not logged
}
}
示例8: GetColorFromImage
private Color GetColorFromImage()
{
var color = Colors.Transparent;
try
{
BitmapSource bitmapSource = ImageColors.Source as BitmapSource;
if (bitmapSource != null)
{
double x = Mouse.GetPosition(ImageColors).X;
x *= bitmapSource.PixelWidth / ImageColors.ActualWidth;
if ((int)x > bitmapSource.PixelWidth - 1)
x = bitmapSource.PixelWidth - 1;
else if (x < 0) x = 0;
double y = Mouse.GetPosition(ImageColors).Y;
y *= bitmapSource.PixelHeight / ImageColors.ActualHeight;
if ((int)y > bitmapSource.PixelHeight - 1)
y = bitmapSource.PixelHeight - 1;
else if (y < 0) y = 0;
CroppedBitmap cb = new CroppedBitmap(bitmapSource, new Int32Rect((int)x, (int)y, 1, 1));
byte[] pixels = new byte[4];
cb.CopyPixels(pixels, 4, 0);
if (pixels[3] == byte.MaxValue)
{
color = Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0]);
}
}
}
catch (Exception ex)
{
Log.Add(ex);
}
return color;
}
示例9: CardPack
public CardPack()
{
_pack = new List<Card>();
Uri uri = new Uri("./Images/cards.png", UriKind.Relative);
source = new BitmapImage(uri);
_cardFronts = new List<CroppedBitmap>();
CardBack = new Image();
int w = source.PixelWidth / 13;
int h = source.PixelHeight/5;
for (int s = 0; s < 4; s++)
{
for (int v = 0; v < 13; v++)
{
int imageIndex = (s*13) + v;
int fx = imageIndex % 13;
int fy = imageIndex / 13;
Int32Rect sourceRect = new Int32Rect(fx * w, fy * h, w, h);
CroppedBitmap front = new CroppedBitmap(source, sourceRect);
sourceRect = new Int32Rect(2 * w, 4 * h, w, h);
CroppedBitmap back = new CroppedBitmap(source, sourceRect);
Image frontImage = new Image {Source = front};
Image backImage = new Image { Source = back };
Card card = new Card((CardSuit)s, (CardValue)v, frontImage, backImage);
_pack.Add(card);
}
}
}
示例10: DrawImage
public void DrawImage(BasicRectangle rectangleDestination, BasicRectangle rectangleSource, IDisposable image)
{
// Make sure the source rectangle width isn't out of bounds
var disposableImage = (DisposableBitmap)image;
var croppedBitmap = new CroppedBitmap(disposableImage.Bitmap, GenericControlHelper.ToInt32Rect(rectangleSource));
_context.DrawImage(croppedBitmap, GenericControlHelper.ToRect(rectangleDestination));
}
示例11: 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;
}
示例12: MakeImage
public Image MakeImage()
{
CroppedBitmap subImg = new CroppedBitmap(RootImage, Region);
Image res = new Image();
res.Source = subImg;
return res;
}
示例13: 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;
}
示例14: TakePartialScreenshot
public Task<BitmapSource> TakePartialScreenshot(Int32Rect rpRect)
{
return TakeScreenshot(r =>
{
var rResult = new CroppedBitmap(r, rpRect);
rResult.Freeze();
return rResult;
});
}
示例15: 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;
}