本文整理汇总了C#中System.Windows.Media.Imaging.BitmapSource类的典型用法代码示例。如果您正苦于以下问题:C# BitmapSource类的具体用法?C# BitmapSource怎么用?C# BitmapSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitmapSource类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了BitmapSource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:kyt8724,项目名称:OperatorRegistration,代码行数:35,代码来源:IDSWebCamHelper.cs
示例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;
}
开发者ID:TNOCS,项目名称:csTouch,代码行数:8,代码来源:Screenshots.cs
示例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;
}
开发者ID:SuperJMN,项目名称:Glass,代码行数:7,代码来源:MultiEngineTest.cs
示例4: Apply
public BitmapSource Apply(BitmapSource image)
{
var grayScale = ToGrayScale(image);
var filter = new Threshold(factor);
var bmp = filter.Apply(grayScale);
return bmp.ToBitmapImage();
}
开发者ID:SuperJMN,项目名称:Glass,代码行数:7,代码来源:ThresholdFilter.cs
示例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;
}
}
}
开发者ID:taesiri,项目名称:electric-field,代码行数:31,代码来源:SolverOutput.xaml.cs
示例6: WriteableBitmap
public WriteableBitmap(
BitmapSource source
)
: base(true) // Use base class virtuals
{
InitFromBitmapSource(source);
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:WriteableBitmap.cs
示例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();
}
开发者ID:JianwenSun,项目名称:cc,代码行数:31,代码来源:TransformedBitmap.cs
示例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;
}
开发者ID:enesyteam,项目名称:EChess,代码行数:33,代码来源:BitmapHelper.cs
示例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;
}
开发者ID:enesyteam,项目名称:EChess,代码行数:33,代码来源:BitmapHelper.cs
示例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));
}
开发者ID:EFanZh,项目名称:EFanZh,代码行数:33,代码来源:Program.cs
示例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;
}
开发者ID:SuperJMN,项目名称:Glass,代码行数:7,代码来源:LeadToolsZoneBasedOcrService.cs
示例12: ImageReceivedEventArgs
public ImageReceivedEventArgs(BitmapSource image)
{
if (image == null)
throw new ArgumentNullException("image");
this.image = image;
}
开发者ID:jlucas9,项目名称:WVU-Lunabotics,代码行数:7,代码来源:JPEGReceiver.cs
示例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);
}
}
开发者ID:stukalin,项目名称:ImageResizer,代码行数:27,代码来源:WpfEncoderPlugin.cs
示例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();
}
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:35,代码来源:ColorConvertedBitmap.cs
示例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);
}
}
开发者ID:BoonieBear,项目名称:TinyMetro,代码行数:31,代码来源:ImageUtils.cs
示例16: ExtractImage
private void ExtractImage(List<WriteableBitmap> tempTiles, BitmapSource image, int spacing, int offset, IProgress<ProgressDialogState> progress = null)
{
var sourceImage = BitmapFactory.ConvertToPbgra32Format(image);
var jump = 16 + spacing;
var totalTiles = ((image.PixelWidth - offset) / jump) * ((image.PixelHeight - offset) / jump);
var currentTile = 0;
for (var y = offset; y < image.PixelHeight; y += jump)
{
for (var x = offset; x < image.PixelWidth; x += jump)
{
var tileImage = new WriteableBitmap(16, 16, 96, 96, PixelFormats.Pbgra32, null);
tileImage.Blit(new System.Windows.Rect(0, 0, 16, 16), sourceImage, new System.Windows.Rect(x, y, 16, 16));
tempTiles.Add(tileImage);
currentTile++;
if (progress != null)
{
progress.Report(new ProgressDialogState() {
ProgressPercentage = currentTile * 100 / totalTiles,
Description = string.Format("Extracting {0} / {1}", currentTile, totalTiles)
});
}
}
}
}
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:27,代码来源:TilesetImporter.cs
示例17: CreateThemedBitmapSource
public static BitmapSource CreateThemedBitmapSource(BitmapSource src, Color bgColor, bool isHighContrast)
{
unchecked {
if (src.Format != PixelFormats.Bgra32)
src = new FormatConvertedBitmap(src, PixelFormats.Bgra32, null, 0.0);
var pixels = new byte[src.PixelWidth * src.PixelHeight * 4];
src.CopyPixels(pixels, src.PixelWidth * 4, 0);
var bg = HslColor.FromColor(bgColor);
int offs = 0;
while (offs + 4 <= pixels.Length) {
var hslColor = HslColor.FromColor(Color.FromRgb(pixels[offs + 2], pixels[offs + 1], pixels[offs]));
double hue = hslColor.Hue;
double saturation = hslColor.Saturation;
double luminosity = hslColor.Luminosity;
double n1 = Math.Abs(0.96470588235294119 - luminosity);
double n2 = Math.Max(0.0, 1.0 - saturation * 4.0) * Math.Max(0.0, 1.0 - n1 * 4.0);
double n3 = Math.Max(0.0, 1.0 - saturation * 4.0);
luminosity = TransformLuminosity(hue, saturation, luminosity, bg.Luminosity);
hue = hue * (1.0 - n3) + bg.Hue * n3;
saturation = saturation * (1.0 - n2) + bg.Saturation * n2;
if (isHighContrast)
luminosity = ((luminosity <= 0.3) ? 0.0 : ((luminosity >= 0.7) ? 1.0 : ((luminosity - 0.3) / 0.4))) * (1.0 - saturation) + luminosity * saturation;
var color = new HslColor(hue, saturation, luminosity, 1.0).ToColor();
pixels[offs + 2] = color.R;
pixels[offs + 1] = color.G;
pixels[offs] = color.B;
offs += 4;
}
BitmapSource newImage = BitmapSource.Create(src.PixelWidth, src.PixelHeight, src.DpiX, src.DpiY, PixelFormats.Bgra32, src.Palette, pixels, src.PixelWidth * 4);
newImage.Freeze();
return newImage;
}
}
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:35,代码来源:ThemedImageCreator.cs
示例18: Save
public static void Save(BitmapSource image, string filename)
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(image));
using (FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write))
encoder.Save(stream);
}
开发者ID:TristramN,项目名称:SourceAFIS,代码行数:7,代码来源:WpfIO.cs
示例19: CompressImageToStream
public Stream CompressImageToStream(BitmapSource compressSource,int height,int width)
{
var writeBmp = new WriteableBitmap(compressSource);
MemoryStream controlStream = new MemoryStream();
writeBmp.SaveJpeg(controlStream, width, height, 0, 100);
return controlStream;
}
开发者ID:rodmanwu,项目名称:dribbble-for-windows-phone-8,代码行数:7,代码来源:CompressLibHelper.cs
示例20: ToGrayScale
private static unsafe BitmapSource ToGrayScale(BitmapSource source)
{
const int PIXEL_SIZE = 4;
int width = source.PixelWidth;
int height = source.PixelHeight;
var bitmap = new WriteableBitmap(source);
bitmap.Lock();
var backBuffer = (byte*)bitmap.BackBuffer.ToPointer();
for (int y = 0; y < height; y++)
{
var row = backBuffer + (y * bitmap.BackBufferStride);
for (int x = 0; x < width; x++)
{
var grayScale = (byte)(((row[x * PIXEL_SIZE + 1]) + (row[x * PIXEL_SIZE + 2]) + (row[x * PIXEL_SIZE + 3])) / 3);
for (int i = 0; i < PIXEL_SIZE; i++)
row[x * PIXEL_SIZE + i] = grayScale;
}
}
bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
bitmap.Unlock();
return bitmap;
}
开发者ID:AndyAn,项目名称:Miiror,代码行数:25,代码来源:iCheckBox.cs
注:本文中的System.Windows.Media.Imaging.BitmapSource类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论