本文整理汇总了C#中System.Windows.Media.Imaging.CroppedBitmap类的典型用法代码示例。如果您正苦于以下问题:C# CroppedBitmap类的具体用法?C# CroppedBitmap怎么用?C# CroppedBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CroppedBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了CroppedBitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:35,代码来源:CroppedImageExample.xaml.cs
示例2: Pieza
public Pieza(int valor, int fila, int columna, CroppedBitmap imagen)
{
Valor = valor;
Fila = fila;
Columna = columna;
Imagen = imagen;
}
开发者ID:jpmermoz,项目名称:EightPuzzle,代码行数:7,代码来源:Pieza.cs
示例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;
}
开发者ID:rakuza,项目名称:YBM2012,代码行数:34,代码来源:WebPublisher.cs
示例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;
}
}
开发者ID:SpoinkyNL,项目名称:Artemis,代码行数:29,代码来源:GradientStopAdder.cs
示例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;
}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:31,代码来源:ScreenshotHelper.cs
示例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);
}
}
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:29,代码来源:PreviewWnd.xaml.cs
示例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
}
}
开发者ID:DeSciL,项目名称:Ogama,代码行数:28,代码来源:ColorPickerUserControl.xaml.cs
示例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;
}
开发者ID:gmikhail,项目名称:gameru-images-uploader,代码行数:33,代码来源:ColorPickerWindow.xaml.cs
示例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);
}
}
}
开发者ID:RedHobbit,项目名称:ClockPatience,代码行数:34,代码来源:CardPack.cs
示例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));
}
开发者ID:pascalfr,项目名称:MPfm,代码行数:7,代码来源:GraphicsContextWrapper.cs
示例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;
}
开发者ID:freeman,项目名称:Paket.VisualStudio,代码行数:8,代码来源:NuGetNameCompletionListProvider.cs
示例12: MakeImage
public Image MakeImage()
{
CroppedBitmap subImg = new CroppedBitmap(RootImage, Region);
Image res = new Image();
res.Source = subImg;
return res;
}
开发者ID:HaKDMoDz,项目名称:tuesdays-are-fun,代码行数:9,代码来源:PartialImageGraphic.cs
示例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;
}
开发者ID:lltcggie,项目名称:StageMapEditor,代码行数:10,代码来源:ObjectChipLibrary.cs
示例14: 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
示例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;
}
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:53,代码来源:ShowMyFace.cs
示例16: upload
public void upload(CroppedBitmap image)
{
PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
pngEncoder.Frames.Add(BitmapFrame.Create(image));
String uniqid = Guid.NewGuid().ToString();
FileStream stream = new FileStream(uniqid, FileMode.Create);
pngEncoder.Save(stream);
stream.Close();
String response = PostToImageShack(uniqid);
parseResponse(response);
}
开发者ID:xbonez,项目名称:Quicksnap,代码行数:12,代码来源:ImageShack.cs
示例17: Crop
public static System.Windows.Controls.Image Crop(Panel displayer, double x, double y, double Width, double Height)
{
if (displayer == null) return null;
Rect rect = new Rect(displayer.RenderSize);
RenderTargetBitmap rtb = new RenderTargetBitmap((int)rect.Right,
(int)rect.Bottom, 96d, 96d, System.Windows.Media.PixelFormats.Default);
rtb.Render(displayer);
var crop = new CroppedBitmap(rtb, new Int32Rect((int)x, (int)y, (int)Width, (int)Height));
return new System.Windows.Controls.Image() { Source = BitmapFrame.Create(crop) };
}
开发者ID:phuongtuanpbt,项目名称:Paint,代码行数:13,代码来源:Croper.cs
示例18: CropImage
protected BitmapSource CropImage(BitmapSource image, Rectangle ClippingRectangle)
{
// Create a CroppedBitmap based off of a xaml defined resource.
CroppedBitmap cb = new CroppedBitmap(
image,
//select region rect
new Int32Rect(
(int)Canvas.GetLeft(ClippingRectangle),
(int)Canvas.GetTop(ClippingRectangle),
(int)ClippingRectangle.Width,
(int)ClippingRectangle.Height));
return cb;
}
开发者ID:Behzadkhosravifar,项目名称:SnippingMultipleScreen,代码行数:14,代码来源:CaptureScreenWindow.xaml.cs
示例19: Calc
void Calc()
{
var xsize = Parent.ImageSource.PixelWidth / Parent.MaxColumns;
var ysize = Parent.ImageSource.PixelHeight / Parent.MaxColumns;
var col = Index % Parent.MaxColumns;
var row = Index / Parent.MaxColumns;
var x = xsize * col;
var y = ysize * row;
var rect = new Int32Rect(x, y, xsize, ysize);
ImageSource = new CroppedBitmap(Parent.ImageSource, rect);
}
开发者ID:Konctantin,项目名称:Puzzle,代码行数:14,代码来源:PuzzleUnit.cs
示例20: AnimationFrameViewModel
public AnimationFrameViewModel(SubTexture subTexture, BitmapImage image)
{
this.Name = subTexture.Name;
this.X = subTexture.X;
this.Y = subTexture.Y;
this.Width = subTexture.Width;
this.Height = subTexture.Height;
Int32 frameIndex = -1;
//There should be 4 padding zeros
Int32.TryParse(Name.Substring(Name.Length - 4, 4), out frameIndex);
this.Index = frameIndex;
this.frameImage = new CroppedBitmap(image, new System.Windows.Int32Rect(x, y, width, height));
}
开发者ID:Nimgoble,项目名称:SpriteAnimator,代码行数:15,代码来源:AnimationFrameViewModel.cs
注:本文中的System.Windows.Media.Imaging.CroppedBitmap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论