本文整理汇总了C#中System.Windows.Media.Imaging.FormatConvertedBitmap.EndInit方法的典型用法代码示例。如果您正苦于以下问题:C# FormatConvertedBitmap.EndInit方法的具体用法?C# FormatConvertedBitmap.EndInit怎么用?C# FormatConvertedBitmap.EndInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.FormatConvertedBitmap
的用法示例。
在下文中一共展示了FormatConvertedBitmap.EndInit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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; }));
}
示例6: BitmapToFormat
/// <summary>
/// Convert bmpSource to format declared in pixFormat.
/// </summary>
/// <param name="bmpSource"></param>
/// <param name="pixFormat"></param>
/// <returns></returns>
public static FormatConvertedBitmap BitmapToFormat(BitmapSource bmpSource,
PixelFormat pixFormat)
{
if (bmpSource == null) { return null; }
FormatConvertedBitmap fcb = new FormatConvertedBitmap();
fcb.BeginInit();
fcb.Source = bmpSource;
fcb.DestinationFormat = pixFormat;
fcb.EndInit();
return fcb;
}
示例7: 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;
}
示例8: BitmapSourceToBitmap
/// <summary>
/// Extension method
/// </summary>
/// <param name="bitmapsource"></param>
/// <returns></returns>
public static Bitmap BitmapSourceToBitmap(this BitmapSource bitmapsource) {
//convert image format
FormatConvertedBitmap src = new FormatConvertedBitmap();
src.BeginInit();
src.Source = bitmapsource;
src.DestinationFormat = System.Windows.Media.PixelFormats.Bgra32;
src.EndInit();
//copy to bitmap
Bitmap bitmap = new Bitmap(src.PixelWidth, src.PixelHeight, PixelFormat.Format32bppArgb);
BitmapData data = bitmap.LockBits(new Rectangle(System.Drawing.Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
src.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height*data.Stride, data.Stride);
bitmap.UnlockBits(data);
return bitmap;
}
示例9: BmpSource2Img
public static System.Drawing.Bitmap BmpSource2Img(BitmapSource bmpsource)
{
//convert image format
var src = new System.Windows.Media.Imaging.FormatConvertedBitmap();
src.BeginInit();
src.Source = bmpsource;
src.EndInit();
//copy to bitmap
Bitmap bitmap = new Bitmap(src.PixelWidth, src.PixelHeight, System.Drawing.Imaging.PixelFormat.DontCare);
var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.DontCare);
src.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
bitmap.UnlockBits(data);
return bitmap;
}
示例10: BtnCon_Click
private void BtnCon_Click(object sender, RoutedEventArgs e)
{
BitmapImage myBitmapImage = new BitmapImage();
// BitmapSource objects like BitmapImage can only have their properties// changed within a BeginInit/EndInit block.
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri("pack://application:,,,/Images/xiaoxiong.jpg");
//myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = myBitmapImage;
// Set the new format to Gray32Float (grayscale).
newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
newFormatedBitmapSource.EndInit();
img2.Source = newFormatedBitmapSource;
}
示例11: Convert
private static ImageSource Convert(BitmapSource input, PixelFormat format)
{
////////// Convert the BitmapSource to a new format ////////////
// Use the BitmapImage created above as the source for a new BitmapSource object
// which is set to a gray scale format using the FormatConvertedBitmap BitmapSource.
// Note: New BitmapSource does not cache. It is always pulled when required.
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
// BitmapSource objects like FormatConvertedBitmap can only have their properties
// changed within a BeginInit/EndInit block.
newFormatedBitmapSource.BeginInit();
// Use the BitmapSource object defined above as the source for this new
// BitmapSource (chain the BitmapSource objects together).
newFormatedBitmapSource.Source = input;
// Set the new format to Gray32Float (grayscale).
newFormatedBitmapSource.DestinationFormat = format;
newFormatedBitmapSource.EndInit();
return newFormatedBitmapSource;
}
示例12: Dither
public static BitmapSource Dither(BitmapSource source, ColorFormat format)
{
if(source.Format == PixelFormats.Indexed8)
{
var rgb = new FormatConvertedBitmap();
rgb.BeginInit();
rgb.Source = source;
rgb.DestinationFormat = PixelFormats.Rgb24;
rgb.EndInit();
source = rgb;
}
var dest = new FormatConvertedBitmap();
dest.BeginInit();
dest.Source = source;
var numColors = (int)Math.Pow(2, (int) format);
var colors = ColorList.Take(numColors).ToList();
dest.DestinationPalette = new BitmapPalette(colors);
dest.DestinationFormat = PixelFormats.Indexed8;
dest.EndInit();
return dest;
}
示例13: ConvertToBitmap
/// <summary>
/// Converts BitmapSource to Bitmap.
/// </summary>
/// <param name="sourceWpf">BitmapSource</param>
/// <returns>Bitmap</returns>
private static Bitmap ConvertToBitmap(BitmapSource sourceWpf)
{
BitmapSource bmpWpf = sourceWpf;
// PixelFormat settings/conversion
System.Drawing.Imaging.PixelFormat formatBmp = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
if (sourceWpf.Format == PixelFormats.Bgr24)
{
formatBmp = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
}
else if (sourceWpf.Format == System.Windows.Media.PixelFormats.Pbgra32)
{
formatBmp = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
}
else if (sourceWpf.Format != System.Windows.Media.PixelFormats.Bgra32)
{
// Convert BitmapSource
FormatConvertedBitmap convertWpf = new FormatConvertedBitmap();
convertWpf.BeginInit();
convertWpf.Source = sourceWpf;
convertWpf.DestinationFormat = PixelFormats.Bgra32;
convertWpf.EndInit();
bmpWpf = convertWpf;
}
// Copy/Convert to Bitmap
Bitmap bmp = new Bitmap(bmpWpf.PixelWidth, bmpWpf.PixelHeight, formatBmp);
Rectangle rect = new Rectangle(Point.Empty, bmp.Size);
BitmapData data = bmp.LockBits(rect, ImageLockMode.WriteOnly, formatBmp);
bmpWpf.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
bmp.UnlockBits(data);
return bmp;
}
示例14: Tick
private void Tick(object sender, EventArgs eventArgs)
{
lock (GL)
{
_sw.Restart();
GL.MakeCurrent();
OnUpdate(GL);
OnRender(GL);
GL.Blit(IntPtr.Zero);
var provider = GL.RenderContextProvider as FBORenderContextProvider;
if (provider == null) return;
var newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.InternalDIBSection.HBitmap);
newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
newFormatedBitmapSource.EndInit();
image.Source = newFormatedBitmapSource;
_sw.Stop();
FPS = 1000.0 / _sw.Elapsed.TotalMilliseconds;
}
}
示例15: timer_Tick
/// <summary>
/// Handles the Tick event of the timer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void timer_Tick(object sender, EventArgs e)
{
// Lock on OpenGL.
lock (gl)
{
// Start the stopwatch so that we can time the rendering.
stopwatch.Restart();
// Make GL current.
gl.MakeCurrent();
// If there is a draw handler, then call it.
var handler = OpenGLDraw;
if (handler != null)
handler(this, eventArgsFast);
else
gl.Clear(SharpGL.OpenGL.GL_COLOR_BUFFER_BIT);
// Draw the FPS.
if (DrawFPS)
{
gl.DrawText(5, 5, 1.0f, 0.0f, 0.0f, "Courier New", 12.0f, string.Format("Draw Time: {0:0.0000} ms ~ {1:0.0} FPS", frameTime, 1000.0 / frameTime));
gl.Flush();
}
// Render.
gl.Blit(IntPtr.Zero);
switch (RenderContextType)
{
case SharpGL.RenderContextType.DIBSection:
{
SharpGL.RenderContextProviders.DIBSectionRenderContextProvider provider = gl.RenderContextProvider as SharpGL.RenderContextProviders.DIBSectionRenderContextProvider;
// TODO: We have to remove the alpha channel - for some reason it comes out as 0.0
// meaning the drawing comes out transparent.
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.DIBSection.HBitmap);
newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
newFormatedBitmapSource.EndInit();
// Copy the pixels over.
image.Source = newFormatedBitmapSource;
}
break;
case SharpGL.RenderContextType.NativeWindow:
break;
case SharpGL.RenderContextType.HiddenWindow:
break;
case SharpGL.RenderContextType.FBO:
{
SharpGL.RenderContextProviders.FBORenderContextProvider provider = gl.RenderContextProvider as SharpGL.RenderContextProviders.FBORenderContextProvider;
// TODO: We have to remove the alpha channel - for some reason it comes out as 0.0
// meaning the drawing comes out transparent.
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.InternalDIBSection.HBitmap);
newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
newFormatedBitmapSource.EndInit();
// Copy the pixels over.
image.Source = newFormatedBitmapSource;
}
break;
default:
break;
}
// Stop the stopwatch.
stopwatch.Stop();
// Store the frame time.
frameTime = stopwatch.Elapsed.TotalMilliseconds;
}
}