本文整理汇总了C#中System.Windows.Media.Imaging.FormatConvertedBitmap类的典型用法代码示例。如果您正苦于以下问题:C# FormatConvertedBitmap类的具体用法?C# FormatConvertedBitmap怎么用?C# FormatConvertedBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FormatConvertedBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了FormatConvertedBitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RgbImageAdapter
public RgbImageAdapter(string path)
{
this.source = new BitmapImage(new Uri(path));
if (source.Format != PixelFormats.Bgra32)
{
source = new FormatConvertedBitmap(source, PixelFormats.Bgra32, null, 0);
}
int width = source.PixelWidth;
int height = source.PixelHeight;
RgbPixel[,] result = new RgbPixel[height, width];
byte[] byteArray = new byte[height * width * 4];
int stride = width * 4;
source.CopyPixels(byteArray, stride, 0);
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
result[i, j] = new RgbPixel
{
Blue = byteArray[(i * width + j) * 4 + 0],
Green = byteArray[(i * width + j) * 4 + 1],
Red = byteArray[(i * width + j) * 4 + 2],
Alpha = byteArray[(i * width + j) * 4 + 3],
};
}
}
image = new RgbImage(result);
}
开发者ID:sangelov,项目名称:Bliss,代码行数:32,代码来源:RgbImageAdapter.cs
示例2: RenderCurve
private byte[] RenderCurve(
ref RenderTargetBitmap rtb,
ref FormatConvertedBitmap fcb,
int width,
IEnumerable<IList<Point>> collection,
double thickness,
int miterLimit,
int height,
int stride)
{
if (rtb == null
|| rtb.PixelWidth != width
|| rtb.PixelHeight != height)
{
rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
fcb = new FormatConvertedBitmap(rtb, DrawingParameter.TargetPixelFormat, DrawingParameter.TargetBitmapPalette, 1);
}
else
{
rtb.Clear();
}
collection
.Select(it =>
{
var visual = _drawingVisualFactory();
visual.Draw(it, thickness, miterLimit, _logicalToScreenMapperFactory());
return visual;
})
.ForEachElement(rtb.Render);
var curvePixels = new byte[stride * height];
fcb.CopyPixels(curvePixels, stride, 0);
return curvePixels;
}
开发者ID:Bruhankovi4,项目名称:Emotyper,代码行数:35,代码来源:WpfExplicitSelectionDrawer.cs
示例3: Button1_Click
public void Button1_Click(object sender, RoutedEventArgs e)
{
try
{
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@text1.Text);
myBitmapImage.EndInit();
FormatConvertedBitmap gray = new FormatConvertedBitmap(myBitmapImage, PixelFormats.Gray4, null, 0);
myImage.Source = gray;
var enc = new JpegBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(gray));
using (var s = File.Create("gray.jpg"))
enc.Save(s);
}
catch
{
text1.Text = "Не верно введен путь";
}
/* public void Button2_Click(object sender, RoutedEventArgs e)
{
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource=new Uri(myImage);
myBitmapImage.EndInit();
var enc = new JpegBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(gray));
using (var s = File.Create("gray.jpg"))
enc.Save(s);*/
}
开发者ID:PokrovskiyEgor,项目名称:ForImg,代码行数:31,代码来源:MainWindow.xaml.cs
示例4: SetSources
/// <summary>
/// Cashes original ImageSource, creates and caches greyscale ImageSource and greyscale opacity mask
/// </summary>
private void SetSources()
{
_sourceC = Source;
try
{
// create and cache greyscale ImageSource
_sourceG = new FormatConvertedBitmap(new BitmapImage(new Uri(TypeDescriptor.GetConverter(Source).ConvertTo(Source, typeof(string)) as string)),
PixelFormats.Gray16, null, 0);
// create Opacity Mask for greyscale image as FormatConvertedBitmap does not keep transparency info
_opacityMaskG = new ImageBrush(_sourceC);
_opacityMaskG.Opacity = 0.5;
this.Source = IsEnabled ? _sourceC : _sourceG;
this.OpacityMask = IsEnabled ? _opacityMaskC : _opacityMaskG;
InvalidateProperty(IsEnabledProperty);
}
catch
{
#if DEBUG
MessageBox.Show(String.Format("The ImageSource used cannot be greyed out.\nUse BitmapImage or URI as a Source in order to allow greyscaling.\nSource type used: {0}", Source.GetType().Name),
"Unsupported Source in GreyableImage", MessageBoxButton.OK, MessageBoxImage.Warning);
#endif // DEBUG
// in case greyscale image cannot be created set greyscale source to original Source
_sourceG = Source;
}
}
开发者ID:andrey-kozyrev,项目名称:LinguaSpace,代码行数:33,代码来源:GreyImage.cs
示例5: ReduceColorDepth
public MemoryStream ReduceColorDepth(Bitmap bmp)
{
var ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Png);
var bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
var newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = bi;
var myPalette = new BitmapPalette(bi, 256);
newFormatedBitmapSource.DestinationPalette = myPalette;
//Set PixelFormats
newFormatedBitmapSource.DestinationFormat = PixelFormats.Indexed8;
newFormatedBitmapSource.EndInit();
var pngBitmapEncoder = new PngBitmapEncoder();
pngBitmapEncoder.Interlace = PngInterlaceOption.Off;
pngBitmapEncoder.Frames.Add(BitmapFrame.Create(newFormatedBitmapSource));
var memstream = new MemoryStream();
pngBitmapEncoder.Save(memstream);
memstream.Position = 0;
return memstream;
}
开发者ID:duckworth,项目名称:DynamicImageDemo,代码行数:32,代码来源:WPFPngColorReducer.cs
示例6: OpenEntry
public override Stream OpenEntry(ArcFile arc, Entry entry)
{
var pent = entry as PnaEntry;
if (null == pent)
return base.OpenEntry (arc, entry);
ImageData image;
using (var input = arc.File.CreateStream (entry.Offset, entry.Size))
image = ImageFormat.Read (input);
var bitmap = image.Bitmap;
if (bitmap.Format.BitsPerPixel != 32)
{
bitmap = new FormatConvertedBitmap (bitmap, PixelFormats.Bgra32, null, 0);
}
int stride = bitmap.PixelWidth * 4;
var pixels = new byte[stride * bitmap.PixelHeight];
bitmap.CopyPixels (pixels, stride, 0);
// restore colors premultiplied by alpha
for (int i = 0; i < pixels.Length; i += 4)
{
int alpha = pixels[i+3];
if (alpha != 0 && alpha != 0xFF)
{
pixels[i] = (byte)(pixels[i] * 0xFF / alpha);
pixels[i+1] = (byte)(pixels[i+1] * 0xFF / alpha);
pixels[i+2] = (byte)(pixels[i+2] * 0xFF / alpha);
}
}
return TgaStream.Create (pent.Info, pixels);
}
开发者ID:Casidi,项目名称:GARbro,代码行数:30,代码来源:ArcPNA.cs
示例7: DrawImage
public static void DrawImage (this ConsoleBuffer @this, ImageSource imageSource, int x, int y, int width, int height)
{
var bmp = imageSource as BitmapSource;
if (bmp == null)
throw new ArgumentException("Only rendering of bitmap source is supported.");
@this.OffsetX(ref x).OffsetY(ref y);
int x1 = x, x2 = x + width, y1 = y, y2 = y + height;
if ([email protected](ref x1, ref y1, ref x2, ref y2))
return;
if (width != bmp.PixelWidth || height != bmp.PixelHeight)
bmp = new TransformedBitmap(bmp, new ScaleTransform((double)width / bmp.PixelWidth, (double)height / bmp.PixelHeight));
if (bmp.Format != PixelFormats.Indexed4)
bmp = new FormatConvertedBitmap(bmp, PixelFormats.Indexed4, BitmapPalettes.Halftone8Transparent, 0.5);
const int bitsPerPixel = 4;
int stride = 4 * (bmp.PixelWidth * bitsPerPixel + 31) / 32;
byte[] bytes = new byte[stride * bmp.PixelHeight];
bmp.CopyPixels(bytes, stride, 0);
for (int iy = y1, py = 0; iy < y2; iy++, py++) {
ConsoleChar[] charsLine = @this.GetLine(iy);
for (int ix = x1, px = 0; ix < x2; ix++, px++) {
int byteIndex = stride * py + px / 2;
int bitOffset = px % 2 == 0 ? 4 : 0;
SetColor(ref charsLine[ix], bmp.Palette, (bytes[byteIndex] >> bitOffset) & 0xF);
}
}
}
开发者ID:jhorv,项目名称:CsConsoleFormat,代码行数:30,代码来源:ConsoleBufferImageExts.cs
示例8: Rasterize
public static bool[,] Rasterize(Point[] points, int width, int height)
{
Contract.Requires(points != null);
Contract.Requires(width > 0);
Contract.Requires(height > 0);
Contract.Requires(width % 8 == 0);
Contract.Ensures(Contract.Result<bool[,]>() != null);
Contract.Ensures(Contract.Result<bool[,]>().GetLength(0) == width);
Contract.Ensures(Contract.Result<bool[,]>().GetLength(1) == height);
var canvas = new Canvas { Background = Brushes.White, Width = width, Height = height };
var polygon = new Polygon { Stroke = Brushes.Black, Fill = Brushes.Black, StrokeThickness = 1, Points = new PointCollection(points) };
canvas.Children.Add(polygon);
RenderOptions.SetEdgeMode(canvas, EdgeMode.Aliased);
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, canvas.DesiredSize.Width, canvas.DesiredSize.Height));
var rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);
rtb.Render(canvas);
var fmb = new FormatConvertedBitmap(rtb, PixelFormats.BlackWhite, null, 0);
var pixels = new byte[width * height / 8];
fmb.CopyPixels(pixels, width / 8, 0);
System.Collections.BitArray ba = new System.Collections.BitArray(pixels);
var result = new bool[width, height];
for (int i = 0, y = 0; y < height; ++y)
for (int x = 0; x < width; ++x, ++i)
result[x, y] = !ba[i];
return result;
}
开发者ID:alexshtf,项目名称:Various-utility-projects,代码行数:34,代码来源:PolygonRasterizer.cs
示例9: MyImageReader
public MyImageReader(string fileName)
{
var filePath = Path.Combine(Environment.CurrentDirectory, fileName);
_bitmap = new FormatConvertedBitmap(new BitmapImage(new Uri("file://" + filePath)), System.Windows.Media.PixelFormats.Bgr32, null, 0);
_pixels = new uint[_bitmap.PixelHeight * _bitmap.PixelWidth];
_bitmap.CopyPixels(_pixels, sizeof(uint) * _bitmap.PixelWidth, 0);
}
开发者ID:jorik041,项目名称:gpgpu-papyrus-demo,代码行数:7,代码来源:MyImageReader.cs
示例10: setPixelFormat2
public static System.Drawing.Bitmap setPixelFormat2(BitmapSource bitmapsource, System.Drawing.Imaging.PixelFormat format)
{
//convert image format
var src = new System.Windows.Media.Imaging.FormatConvertedBitmap();
src.BeginInit();
src.Source = bitmapsource;
if (format == System.Drawing.Imaging.PixelFormat.Format1bppIndexed)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.BlackWhite;
}
if (format == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.Gray8;
}
if (format == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.Bgr24;
}
if (format == System.Drawing.Imaging.PixelFormat.Format32bppRgb)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.Bgr32;
}
src.EndInit();
//copy to bitmap
Bitmap bitmap = new Bitmap(src.PixelWidth, src.PixelHeight, format);
var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, format);
src.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
bitmap.UnlockBits(data);
return bitmap;
}
开发者ID:IntelisoftDev,项目名称:NgScanApp,代码行数:32,代码来源:ImageProc.cs
示例11: 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
示例12: BitmapSourceLuminanceSource
/// <summary>
/// Initializes a new instance of the <see cref="BitmapSourceLuminanceSource"/> class.
/// </summary>
/// <param name="bitmap">The bitmap.</param>
public BitmapSourceLuminanceSource(BitmapSource bitmap)
: base(bitmap.PixelWidth, bitmap.PixelHeight)
{
switch (bitmap.Format.ToString())
{
case "Bgr24":
case "Bgr32":
CalculateLuminanceBGR(bitmap);
break;
case "Bgra32":
CalculateLuminanceBGRA(bitmap);
break;
case "Rgb24":
CalculateLuminanceRGB(bitmap);
break;
case "Bgr565":
CalculateLuminanceBGR565(bitmap);
break;
default:
// there is no special conversion routine to luminance values
// we have to convert the image to a supported format
bitmap = new FormatConvertedBitmap(bitmap, PixelFormats.Bgra32, null, 0);
CalculateLuminanceBGR(bitmap);
break;
}
}
开发者ID:Binjaaa,项目名称:ZXing.Net.Mobile,代码行数:30,代码来源:BitmapSourceLuminanceSource.cs
示例13: SetIcon
internal void SetIcon(string fileName)
{
var bitmapSource = new BitmapImage();
bitmapSource.BeginInit();
bitmapSource.UriSource = new Uri(fileName);
// ensure that we resize to the correct dimensions
bitmapSource.DecodePixelHeight = 46;
bitmapSource.DecodePixelWidth = 46;
bitmapSource.EndInit();
var pbgra32Image = new FormatConvertedBitmap(bitmapSource, System.Windows.Media.PixelFormats.Pbgra32, null, 0);
var bmp = new System.Windows.Media.Imaging.WriteableBitmap(pbgra32Image);
var images = new List<BandIcon>() { bmp.ToBandIcon(), bmp.ToBandIcon() };
Strapp.SetImageList(Strapp.TileId, images, 0);
_tiles.UpdateStrapp(Strapp);
// this should refresh all bindings into the Strapp (in particular, the image)
NotifyPropertyChanged("Strapp");
}
开发者ID:jehy,项目名称:unBand,代码行数:26,代码来源:BandStrapp.cs
示例14: ConvertToOtherPixelFormat
public static BitmapImage ConvertToOtherPixelFormat(BitmapSource source, PixelFormat format)
{
var newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = source;
newFormatedBitmapSource.DestinationFormat = format;
newFormatedBitmapSource.EndInit();
return BitmapSourceToBitmapImage(newFormatedBitmapSource.Source);
}
开发者ID:kib357,项目名称:Ester2,代码行数:9,代码来源:WorkWithImages.cs
示例15: GetFormatConvertedBitmap
public static FormatConvertedBitmap GetFormatConvertedBitmap(SWM.PixelFormat pf, BitmapSource bs)
{
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = bs;
newFormatedBitmapSource.DestinationFormat = pf;
newFormatedBitmapSource.EndInit();
return newFormatedBitmapSource;
}
开发者ID:huangjia2107,项目名称:MyControls,代码行数:10,代码来源:GraphicAlgorithm.cs
示例16: ToGdiBitmap
public static Bitmap ToGdiBitmap(BitmapSource bmp)
{
// below code refernces blog entry by luche:
// http://www.ruche-home.net/%A4%DC%A4%E4%A4%AD%A4%B4%A4%C8/2011-08-02/CopyPixels%20%A5%E1%A5%BD%A5%C3%A5%C9%A4%F2%CD%D1%A4%A4%A4%BF%20WPF%20BitmapSource%20%A4%AB%A4%E9%20GDI%20Bitmap%20%A4%D8%A4%CE%CA%D1%B4%B9
if (bmp.Format != PixelFormats.Bgra32)
{
// convert format
bmp = new FormatConvertedBitmap(bmp,
PixelFormats.Bgra32, null, 0);
bmp.Freeze();
}
// prepare values
var width = (int)bmp.Width;
var height = (int)bmp.Height;
var stride = width * 4;
// prepare buffer
var buffer = new byte[stride * height];
// copy to byte array
bmp.CopyPixels(buffer, stride, 0);
// create bitmap
var result = new Bitmap(width, height, SDI::PixelFormat.Format32bppArgb);
// set bitmap content
try
{
// locking bits
SDI::BitmapData bd = null;
try
{
bd = result.LockBits(new Rectangle(0, 0, width, height),
SDI::ImageLockMode.WriteOnly, SDI::PixelFormat.Format32bppArgb);
Marshal.Copy(buffer, 0, bd.Scan0, buffer.Length);
}
finally
{
if (bd != null)
{
result.UnlockBits(bd);
}
}
}
catch
{
result.Dispose();
throw;
}
return result;
}
开发者ID:Kei-Nanigashi,项目名称:StarryEyes,代码行数:54,代码来源:ImageInterop.cs
示例17: LoadBitmap
private static BitmapSource LoadBitmap(string path)
{
BitmapSource bitmapSource = new BitmapImage(new Uri(Path.GetFullPath(path)));
if (bitmapSource.Format != workingFormat)
{
bitmapSource = new FormatConvertedBitmap(bitmapSource, workingFormat, null, 0.5);
}
return bitmapSource;
}
开发者ID:EFanZh,项目名称:EFanZh,代码行数:11,代码来源:Program.cs
示例18: 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
示例19: Convert
/// <summary>
/// Converts a bitmap and returns the result.
/// </summary>
/// <param name="bitmap">The bitmap to convert.</param>
/// <returns>The result.</returns>
public BitmapSource Convert(BitmapSource bitmap)
{
BitmapSource result = bitmap;
if(bitmap.Format != _format)
result = new FormatConvertedBitmap(result, _format, null, 0);
if(Rotate != 0)
result = new TransformedBitmap(result, new RotateTransform(Rotate));
return result;
}
开发者ID:skpdvdd,项目名称:Pdf2KT,代码行数:17,代码来源:BitmapSourceConverter.cs
示例20: SetGrayscale
private static void SetGrayscale(System.Windows.Controls.Image img)
{
img.IsEnabled = false;
FormatConvertedBitmap bitmap = new FormatConvertedBitmap();
bitmap.BeginInit();
bitmap.Source = (BitmapSource)img.Source;
bitmap.DestinationFormat = PixelFormats.Gray32Float;
bitmap.EndInit();
img.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => { img.Source = bitmap; }));
}
开发者ID:nick121212,项目名称:xima_desktop3,代码行数:12,代码来源:ImageAttached.cs
注:本文中的System.Windows.Media.Imaging.FormatConvertedBitmap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论