本文整理汇总了C#中System.Windows.Media.Imaging.PngBitmapEncoder类的典型用法代码示例。如果您正苦于以下问题:C# PngBitmapEncoder类的具体用法?C# PngBitmapEncoder怎么用?C# PngBitmapEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PngBitmapEncoder类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了PngBitmapEncoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ButtonSave_Click
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
var rect = new Rect { Width = 512, Height = 384 };
var dv = new DrawingVisual();
var dc = dv.RenderOpen();
dc.PushTransform(new TranslateTransform(-rect.X, -rect.Y));
dc.DrawRectangle(InkCanvasMain.Background, null, rect);
InkCanvasMain.Strokes.Draw(dc);
dc.Close();
var rtb = new RenderTargetBitmap((int)rect.Width, (int)rect.Height, 96, 96, PixelFormats.Default);
rtb.Render(dv);
var enc = new PngBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(rtb));
var fn = TextBoxFileName.Text;
if (!fn.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) fn += ".png";
using (Stream s = File.Create(TegakiImageFolder + "/" + fn))
{
enc.Save(s);
}
((TegakiWindowViewModel)DataContext).AddToMediaList(System.IO.Path.GetFullPath(TegakiImageFolder + "/" + fn));
Close();
}
开发者ID:kb10uy,项目名称:Kbtter4,代码行数:25,代码来源:TegakiWindow.xaml.cs
示例2: Create3DViewPort
private void Create3DViewPort()
{
var hvp3d = new HelixViewport3D();
Viewport3D vp3d = new Viewport3D();
var lights = new DefaultLights();
var tp = new Teapot();
hvp3d.Children.Add(lights);
hvp3d.Children.Add(tp);
vp3d = hvp3d.Viewport;
tata.Children.Add(vp3d); // comenter ca pour test
/* MEGA TEST DE L'ESPACE SUBSAHARIEN */
RenderTargetBitmap bmp = new RenderTargetBitmap(800, 800, 96, 96, PixelFormats.Pbgra32);
var rect = new Rect(0, 0, 800, 800);
vp3d.Measure(new Size(800, 800));
vp3d.Arrange(rect);
vp3d.InvalidateVisual();
bmp.Render(vp3d);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bmp));
String filepath = "C:\\Users\\Remi\\Desktop\\canardmasque.png";
using (Stream stm = File.Create(filepath))
{
png.Save(stm);
}
}
开发者ID:remi-hernandez,项目名称:renderHelixViewPort3d,代码行数:32,代码来源:MainWindow.xaml.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: Encode
public static byte[] Encode(String path)
{
byte[] encoded;
try
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.UriSource = new Uri(path, UriKind.RelativeOrAbsolute);
bitmap.EndInit();
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
using (var stream = new MemoryStream())
{
encoder.Save(stream);
encoded = stream.ToArray();
}
return encoded;
}
catch (Exception)
{
return null;
}
}
开发者ID:PYO2016,项目名称:Client,代码行数:27,代码来源:PyoEncoder.cs
示例5: CreateCursor
public static Cursor CreateCursor(UIElement element, int xHotSpot,
int yHotSpot)
{
element.Measure(new Size(double.PositiveInfinity,
double.PositiveInfinity));
element.Arrange(new Rect(0, 0, element.DesiredSize.Width,
element.DesiredSize.Height));
RenderTargetBitmap rtb =
new RenderTargetBitmap((int)element.DesiredSize.Width,
(int)element.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
rtb.Render(element);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
ms.Close();
ms.Dispose();
Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);
bmp.Dispose();
return cur;
}
开发者ID:heinzsack,项目名称:DEV,代码行数:30,代码来源:CursorHelper.cs
示例6: SavePatient
private void SavePatient()
{
// string paths = @"c:\amHealth\images";
string filePath = @"c:\amHealth\\images\" +fname.Text+"-"+lname.Text +".jpg";
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapSource)imgCapture.Source));
using (FileStream stream = new FileStream(filePath, FileMode.Create))
encoder.Save(stream);
_patient = App.amApp.Patients.Add();
_patient.Lname = lname.Text;
_patient.Fname = fname.Text;
_patient.Gender = gender.Text;
_patient.Dob = dob.Text;
_patient.Height = height.Text;
_patient.Weight = weight.Text;
_patient.Phone = phone.Text;
_patient.Region = region.Text;
_patient.Sync = "F";
_patient.Email = email.Text;
_patient.Org = "test";
_patient.Image = fname.Text + "-" + lname.Text + ".jpg";
_patient.Save();
System.Windows.MessageBox.Show("Patient saved ");
this.DialogResult = true;
}
开发者ID:WereDouglas,项目名称:amHealth,代码行数:30,代码来源:AddPatient.xaml.cs
示例7: Convert
public void Convert(IEnumerable<IAssetImageSource> sources, string target, VisualAssetInfo visualAsset)
{
if (sources == null)
{
throw new ArgumentNullException("sources");
}
if (string.IsNullOrEmpty(target))
{
throw new ArgumentNullException("target");
}
if (visualAsset == null)
{
throw new ArgumentNullException("visualAsset");
}
var rectangle = this.GetRectangleBounds(visualAsset.Width, visualAsset.Height, visualAsset.Margin);
var drawingVisual = this.CreateDrawingVisual(sources, rectangle);
var targetBitmap = new RenderTargetBitmap(visualAsset.Width, visualAsset.Height, 96, 96, PixelFormats.Pbgra32);
targetBitmap.Render(drawingVisual);
var png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(targetBitmap));
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write))
{
png.Save(stream);
}
}
开发者ID:duracellko,项目名称:WindowsApp-VisualAssets,代码行数:29,代码来源:ImageAssetConverter.cs
示例8: ButtonScreenshotClick
/// <summary>
/// Handles the user clicking on the screenshot button
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void ButtonScreenshotClick(object sender, RoutedEventArgs e)
{
if (null == this.sensor)
{
this.statusBarText.Text = Properties.Resources.ConnectDeviceFirst;
return;
}
// create a png bitmap encoder which knows how to save a .png file
BitmapEncoder encoder = new PngBitmapEncoder();
// create frame from the writable bitmap and add to encoder
encoder.Frames.Add(BitmapFrame.Create(this.colorBitmap));
string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat);
string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
string path = Path.Combine(myPhotos, "KinectSnapshot-" + time + ".png");
// write the new file to disk
try
{
using (FileStream fs = new FileStream(path, FileMode.Create))
{
encoder.Save(fs);
}
this.statusBarText.Text = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.ScreenshotWriteSuccess, path);
}
catch (IOException)
{
this.statusBarText.Text = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.ScreenshotWriteFailed, path);
}
}
开发者ID:KenKoji,项目名称:kenkoji-33,代码行数:40,代码来源:MainWindow.xaml.cs
示例9: 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
示例10: ExportToPng
public static byte[] ExportToPng(this FrameworkElement surface)
{
var transform = surface.LayoutTransform;
surface.LayoutTransform = null;
var size = new Size(surface.ActualWidth, surface.ActualHeight);
surface.Measure(size);
surface.Arrange(new Rect(size));
var renderBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32);
renderBitmap.Render(surface);
try
{
using (var outStream = new MemoryStream())
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(outStream);
return outStream.ToArray();
}
}
finally
{
surface.LayoutTransform = transform;
}
}
开发者ID:PeletonSoft,项目名称:Sketch,代码行数:27,代码来源:ImageCaptureHelper.cs
示例11: getImageFromControl
/// <summary>
/// Convert any control to a PngBitmapEncoder
/// </summary>
/// <param name="controlToConvert">The control to convert to an ImageSource</param>
/// <returns>The returned ImageSource of the controlToConvert</returns>
private static PngBitmapEncoder getImageFromControl(Control controlToConvert)
{
// save current canvas transform
Transform transform = controlToConvert.LayoutTransform;
// get size of control
Size sizeOfControl = new Size(controlToConvert.ActualWidth, controlToConvert.ActualHeight);
// measure and arrange the control
controlToConvert.Measure(sizeOfControl);
// arrange the surface
controlToConvert.Arrange(new Rect(sizeOfControl));
// craete and render surface and push bitmap to it
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((Int32)sizeOfControl.Width, (Int32)sizeOfControl.Height, 96d, 96d, PixelFormats.Pbgra32);
// now render surface to bitmap
renderBitmap.Render(controlToConvert);
// encode png data
PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
// puch rendered bitmap into it
pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));
// return encoder
return pngEncoder;
}
开发者ID:SomeGuyinIN,项目名称:hefnycopter,代码行数:30,代码来源:Control2ImageConverter.cs
示例12: SaveAsPng
public static void SaveAsPng(this BitmapSource bitmap, string filename) {
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
using (var s = File.Create(filename)) {
encoder.Save(s);
}
}
开发者ID:gro-ove,项目名称:actools,代码行数:7,代码来源:BitmapSourceExtension.cs
示例13: SaveImage
private void SaveImage(string filePath)
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapSource) imageScreenshot.Source));
using (var stream = new FileStream(filePath, FileMode.Create))
encoder.Save(stream);
}
开发者ID:t3hm00kz,项目名称:Assembly,代码行数:7,代码来源:HaloScreenshot.xaml.cs
示例14: GetPngImage
/// <summary>
/// Gets a PNG "screenshot" of the current UIElement
/// </summary>
/// <param name="source">UIElement to screenshot</param>
/// <param name="scale">Scale to render the screenshot</param>
/// <returns>Byte array of PNG data</returns>
public static byte[] GetPngImage(this UIElement source, double scale = 1)
{
var actualHeight = source.RenderSize.Height;
var actualWidth = source.RenderSize.Width;
var renderHeight = actualHeight * scale;
var renderWidth = actualWidth * scale;
var renderTarget = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, 96, 96, PixelFormats.Pbgra32);
var sourceBrush = new VisualBrush(source);
var drawingVisual = new DrawingVisual();
var drawingContext = drawingVisual.RenderOpen();
using (drawingContext)
{
drawingContext.PushTransform(new ScaleTransform(scale, scale));
drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Size(actualWidth, actualHeight)));
}
renderTarget.Render(drawingVisual);
var pngEncoder = new PngBitmapEncoder();
pngEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
Byte[] imageArray;
using (var outputStream = new MemoryStream())
{
pngEncoder.Save(outputStream);
imageArray = outputStream.ToArray();
}
return imageArray;
}
开发者ID:secretGeek,项目名称:karcero,代码行数:39,代码来源:Screenshot.cs
示例15: SaveToPng
public void SaveToPng( Canvas surface, string file )
{
// Save current canvas transform
var transform = surface.LayoutTransform;
// reset current transform (in case it is scaled or rotated)
surface.LayoutTransform = null;
var size = new Size( 1600, 900 );
// Attentation: Measure and arrange the surface !
surface.Measure( size );
surface.Arrange( new Rect( size ) );
var renderBitmap = new RenderTargetBitmap( (int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32 );
var bounds = VisualTreeHelper.GetDescendantBounds( surface );
var dv = new DrawingVisual();
using ( var ctx = dv.RenderOpen() )
{
var vb = new VisualBrush( surface );
ctx.DrawRectangle( vb, null, new Rect( new Point(), bounds.Size ) );
}
renderBitmap.Render( dv );
using ( var outStream = new FileStream( file, FileMode.OpenOrCreate, FileAccess.Write ) )
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add( BitmapFrame.Create( renderBitmap ) );
encoder.Save( outStream );
}
// Restore previously saved layout
surface.LayoutTransform = transform;
}
开发者ID:JackWangCUMT,项目名称:Plainion.Whiteboard,代码行数:34,代码来源:PersistenceService.cs
示例16: RenderBrush
/// <summary>
/// Renders the brush.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
/// <param name="brush">
/// The brush.
/// </param>
/// <param name="w">
/// The w.
/// </param>
/// <param name="h">
/// The h.
/// </param>
public static void RenderBrush(string path, Brush brush, int w, int h)
{
var ib = brush as ImageBrush;
if (ib != null)
{
var bi = ib.ImageSource as BitmapImage;
if (bi != null)
{
w = bi.PixelWidth;
h = bi.PixelHeight;
}
}
var bmp = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32);
var rect = new Grid
{
Background = brush,
Width = 1,
Height = 1,
LayoutTransform = new ScaleTransform(w, h)
};
rect.Arrange(new Rect(0, 0, w, h));
bmp.Render(rect);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (Stream stm = File.Create(path))
{
encoder.Save(stm);
}
}
开发者ID:BEEden,项目名称:Diplomarbeit,代码行数:47,代码来源:Exporter.cs
示例17: AcquireClipboardContent
public void AcquireClipboardContent()
{
try
{
if (Clipboard.ContainsAudio())
{
Audio = Clipboard.GetAudioStream();
}
else if (Clipboard.ContainsFileDropList())
{
FileDropList = Clipboard.GetFileDropList();
}
else if (Clipboard.ContainsImage())
{
using (MemoryStream ms = new MemoryStream())
{
BitmapSource img = Clipboard.GetImage();
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(img));
encoder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
Image = ms.ToArray();
}
}
else if (Clipboard.ContainsText())
{
Text = Clipboard.GetText();
}
else
{
isEmpty = true;
}
}
catch (Exception ex) { Trace.TraceError("Exception in CopyOnClipboard()", ex.StackTrace); }
}
开发者ID:giu-fio,项目名称:remote-control-server,代码行数:35,代码来源:MyClibpoard.cs
示例18: SaveBitmap
private static void SaveBitmap(BitmapSource bitmap, string destination)
{
BitmapEncoder encoder;
switch (Path.GetExtension(destination).ToUpperInvariant())
{
case ".BMP":
encoder = new BmpBitmapEncoder();
break;
case ".GIF":
encoder = new GifBitmapEncoder();
break;
case ".JPG":
encoder = new JpegBitmapEncoder() { QualityLevel = 100 };
break;
case ".PNG":
encoder = new PngBitmapEncoder();
break;
case ".TIF":
encoder = new TiffBitmapEncoder() { Compression = TiffCompressOption.Zip };
break;
default:
throw new NotSupportedException("Not supported output extension.");
}
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.Save(new FileStream(destination, FileMode.Create));
}
开发者ID:EFanZh,项目名称:EFanZh,代码行数:33,代码来源:Program.cs
示例19: Export
/// <summary>
/// Exports the specified viewport.
/// </summary>
/// <param name="viewport">
/// The viewport.
/// </param>
public void Export(Viewport3D viewport)
{
int m = this.OversamplingMultiplier;
var background = this.Background;
if (background == null)
{
background = Brushes.Transparent;
}
var bmp = Viewport3DHelper.RenderBitmap(viewport, background, m);
BitmapEncoder encoder;
string ext = Path.GetExtension(this.FileName);
switch (ext.ToLower())
{
case ".jpg":
var jpg = new JpegBitmapEncoder();
jpg.Frames.Add(BitmapFrame.Create(bmp));
encoder = jpg;
break;
case ".png":
var png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bmp));
encoder = png;
break;
default:
throw new InvalidOperationException("Not supported file format.");
}
using (Stream stm = File.Create(this.FileName))
{
encoder.Save(stm);
}
}
开发者ID:sivarajankumar,项目名称:dentalsmile,代码行数:40,代码来源:BitmapExporter.cs
示例20: SaveAsImage
public static void SaveAsImage(FrameworkElement visual)
{
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.DefaultExt = ".png";
dlg.Filter = "PNG Image (.png)|*.png|JPEG Image (.jpg)|*.jpg";
if (dlg.ShowDialog().Value)
{
BitmapSource img = (BitmapSource)ToImageSource(visual);
FileStream stream = new FileStream(dlg.FileName, FileMode.Create);
BitmapEncoder encoder = null; // new BitmapEncoder();
if (dlg.SafeFileName.ToLower().EndsWith(".png"))
{
encoder = new PngBitmapEncoder();
}
else
{
encoder = new JpegBitmapEncoder();
}
encoder.Frames.Add(BitmapFrame.Create(img));
encoder.Save(stream);
stream.Close();
}
}
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:27,代码来源:Common.cs
注:本文中的System.Windows.Media.Imaging.PngBitmapEncoder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论