本文整理汇总了C#中System.Windows.Media.Imaging.BitmapSource类的典型用法代码示例。如果您正苦于以下问题:C# BitmapSource类的具体用法?C# BitmapSource怎么用?C# BitmapSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitmapSource类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了BitmapSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveImageCapture
/// <summary>
/// Scripter: YONGTOK KIM
/// Description : Save the image to the file.
/// </summary>
public static string SaveImageCapture(BitmapSource bitmap)
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.QualityLevel = 100;
// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Image"; // Default file name
dlg.DefaultExt = ".Jpg"; // Default file extension
dlg.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension
// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save Image
string filename = dlg.FileName;
FileStream fstream = new FileStream(filename, FileMode.Create);
encoder.Save(fstream);
fstream.Close();
return filename;
}
return null;
}
示例2: GetImageByteArray
// get raw bytes from BitmapImage using BitmapImage.CopyPixels
private byte[] GetImageByteArray(BitmapSource bi)
{
var rawStride = (bi.PixelWidth * bi.Format.BitsPerPixel + 7) / 8;
var result = new byte[rawStride * bi.PixelHeight];
bi.CopyPixels(result, rawStride, 0);
return result;
}
示例3: ExtractBestTextCandidate
private string ExtractBestTextCandidate(BitmapSource bitmap, ITextualDataFilter filter, Symbology symbology)
{
var page = Engine.Recognize(bitmap, RecognitionConfiguration.FromSingleImage(bitmap, filter, symbology));
var zone = page.RecognizedZones.First();
return zone.RecognitionResult.Text;
}
示例4: Apply
public BitmapSource Apply(BitmapSource image)
{
var grayScale = ToGrayScale(image);
var filter = new Threshold(factor);
var bmp = filter.Apply(grayScale);
return bmp.ToBitmapImage();
}
示例5: SolverOutput
public SolverOutput(BitmapSource data, List<Solver.Colorizer> colorpalette, IEnumerable<Charge> charges)
{
InitializeComponent();
_outputdata = data;
_charges = new List<Charge>(charges);
gridField.Background = new ImageBrush(data);
recMapHelper.Fill = Helper.ConvertToBrush(colorpalette);
foreach (Charge charge in _charges)
{
if (charge.IsActive)
{
var newfPoint = new FieldPoint
{
Height = 6,
Width = 6,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, 0, 0, 0),
Mcharge = charge
};
var tgroup = new TransformGroup();
var tt = new TranslateTransform(charge.Location.X + 14, charge.Location.Y + 14);
tgroup.Children.Add(tt);
gridField.Children.Add(newfPoint);
newfPoint.RenderTransform = tgroup;
}
}
}
示例6: WriteableBitmap
public WriteableBitmap(
BitmapSource source
)
: base(true) // Use base class virtuals
{
InitFromBitmapSource(source);
}
示例7: TransformedBitmap
/// <summary>
/// Construct a TransformedBitmap with the given newTransform
/// </summary>
/// <param name="source">BitmapSource to apply to the newTransform to</param>
/// <param name="newTransform">Transform to apply to the bitmap</param>
public TransformedBitmap(BitmapSource source, Transform newTransform)
: base(true) // Use base class virtuals
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (newTransform == null)
{
throw new InvalidOperationException(SR.Get(SRID.Image_NoArgument, "Transform"));
}
if (!CheckTransform(newTransform))
{
throw new InvalidOperationException(SR.Get(SRID.Image_OnlyOrthogonal));
}
_bitmapInit.BeginInit();
Source = source;
Transform = newTransform;
_bitmapInit.EndInit();
FinalizeCreation();
}
示例8: BMPFromBitmapSource
public static System.Drawing.Bitmap BMPFromBitmapSource(BitmapSource source, int iCount)
{
//int width = 128;
//int height = 128;
//int stride = width;
//byte[] pixels = new byte[height * stride];
//// Define the image palette
//BitmapPalette myPalette = BitmapPalettes.Halftone256;
//// Creates a new empty image with the pre-defined palette
//BitmapSource image = BitmapSource.Create(
// width,
// height,
// 96,
// 96,
// PixelFormats.Indexed8,
// myPalette,
// pixels,
// stride);
FileStream stream = new FileStream("image" + iCount + ".BMP", FileMode.Create);
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
//TextBlock myTextBlock = new TextBlock();
//myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
//encoder.Interlace = PngInterlaceOption.On;
encoder.Frames.Add(BitmapFrame.Create(source));
encoder.Save(stream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
return bitmap;
}
示例9: GetBitmap
/// <summary>
/// Chuyển đổi BitmapSource thành Bitmap
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static System.Drawing.Bitmap GetBitmap(BitmapSource source)
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap
(
source.PixelWidth,
source.PixelHeight,
System.Drawing.Imaging.PixelFormat.Format32bppRgb
);
System.Drawing.Imaging.BitmapData data = bmp.LockBits
(
new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size),
System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format32bppRgb
);
source.CopyPixels
(
Int32Rect.Empty,
data.Scan0,
data.Height * data.Stride,
data.Stride
);
bmp.UnlockBits(data);
return bmp;
}
示例10: 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));
}
示例11: RecognizeScaleEachVariation
public IEnumerable<RecognitionResult> RecognizeScaleEachVariation(BitmapSource bitmap, ZoneConfiguration config)
{
var bitmaps = BitmapGenerators.SelectMany(g => g.Generate(bitmap));
var scaled = bitmaps.Select(ScaleIfEnabled);
var recognitions = scaled.SelectMany(bmp => RecognizeCore(config, bmp));
return recognitions;
}
示例12: ImageReceivedEventArgs
public ImageReceivedEventArgs(BitmapSource image)
{
if (image == null)
throw new ArgumentNullException("image");
this.image = image;
}
示例13: Write
public void Write(BitmapSource i, Stream s)
{
BitmapEncoder encoder = null;
if (MimeType.Equals("image/jpeg"))
{
encoder = new JpegBitmapEncoder();
((JpegBitmapEncoder)encoder).QualityLevel = localSettings.Quality;
}
else if (MimeType.Equals("image/png"))
{
encoder = new PngBitmapEncoder();
}
else if (MimeType.Equals("image/gif"))
{
encoder = new GifBitmapEncoder();
encoder.Palette = new BitmapPalette(i, 256);
}
encoder.Frames.Add(BitmapFrame.Create(i));
using (MemoryStream outputStream = new MemoryStream())
{
encoder.Save(outputStream);
outputStream.WriteTo(s);
}
}
示例14: ColorConvertedBitmap
/// <summary>
/// Construct a ColorConvertedBitmap
/// </summary>
/// <param name="source">Input BitmapSource to color convert</param>
/// <param name="sourceColorContext">Source Color Context</param>
/// <param name="destinationColorContext">Destination Color Context</param>
/// <param name="format">Destination Pixel format</param>
public ColorConvertedBitmap(BitmapSource source, ColorContext sourceColorContext, ColorContext destinationColorContext, PixelFormat format)
: base(true) // Use base class virtuals
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (sourceColorContext == null)
{
throw new ArgumentNullException("sourceColorContext");
}
if (destinationColorContext == null)
{
throw new ArgumentNullException("destinationColorContext");
}
_bitmapInit.BeginInit();
Source = source;
SourceColorContext = sourceColorContext;
DestinationColorContext = destinationColorContext;
DestinationFormat = format;
_bitmapInit.EndInit();
FinalizeCreation();
}
示例15: SaveBitmapSource2File
public static void SaveBitmapSource2File(string filename, BitmapSource image5)
{
try
{
if (filename == null)
{
_logger.Warn("SaveBitmapSource2File: filename is null");
return;
}
if (image5 == null)
{
_logger.Error(string.Format("Survey UI: Trying to saved a null image source from file {0}", filename));
return;
}
if (filename != string.Empty)
{
using (FileStream stream5 = new FileStream(filename, FileMode.Create))
{
PngBitmapEncoder encoder5 = new PngBitmapEncoder();
encoder5.Frames.Add(BitmapFrame.Create(image5));
encoder5.Save(stream5);
stream5.Close();
}
}
}
catch (Exception ex)
{
_logger.Error("SaveBitmapSource2File", ex);
}
}