private BitmapSource CreateWhiteNoizeBmp(int width, int height) { var dataSource = DataSource; Random rnd = new Random(); int[] pixels = new int[width * height]; for (int i = 0; i < width * height; i++) { HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4); int argb = color.ToArgb(); pixels[i] = argb; } //var whiteNoizeBmp = WriteableBitmap.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, pixels, width * 4); var contentBounds = dataSource.Grid.GetGridBounds(); Viewport2D.SetContentBounds(this, contentBounds); int[] effectivePixels = CreateConvolutionArray(width, height, pixels); var filter = new NormalizeFilter(); filter.Filter(effectivePixels, width, height); var result = WriteableBitmap.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, effectivePixels, width * 4); //ScreenshotHelper.SaveBitmapToFile(result, "1.png"); return(result); }
public MainWindow() { InitializeComponent(); // The buffer we use BackgroundImage = new byte[320 * 240]; // We need to pin the foreground buffer to make sure // the int buffer is aligned in memory. foregroundBuffer = new int[64 * 48]; foregroundBufferHandle = GCHandle.Alloc(foregroundBuffer, GCHandleType.Pinned); // Try creating a new image with a custom palette. List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>(); colors.Add(System.Windows.Media.Colors.Red); colors.Add(System.Windows.Media.Colors.Blue); colors.Add(System.Windows.Media.Colors.Green); BitmapPalette myPalette = new BitmapPalette(colors); // Calculate the stride int stride = WIDTH * (32 + 7) / 8; byte[] pixels = new byte[stride * HEIGHT]; // Create bitmap source _source = WriteableBitmap.Create( WIDTH, HEIGHT, 96, 96, System.Windows.Media.PixelFormats.Pbgra32, myPalette, pixels, stride); // Create destination writeable bitmap _destination = new WriteableBitmap(_source); // Do stuff when window loaded Loaded += OnLoaded; // Create fake timer _tImageStreamEmulator = new Timer(16); _tImageStreamEmulator.Elapsed += OnNewImageAvailable; // Start fake stream _tImageStreamEmulator.Start(); }
void renderClock_Tick(object sender, EventArgs e) { try { bool stopClock = done; if (!abort) { theImage.Source = WriteableBitmap.Create(width, height, 96, 96, PixelFormats.Bgr32, null, bytes, width * 4); } if (stopClock || abort) { renderClock.Stop(); } } catch (OutOfMemoryException) { GC.Collect(); } }
public BitmapSource Draw() { int count = size * size; int[] pixels = new int[count]; for (int i = 0; i < count; i++) { int x = i % size; int y = i / size; int pixel = GetColor(xMin + x * (xMax - xMin) / (size - 1), yMin + y * (yMax - yMin) / (size - 1)); pixels[i] = pixel; } var bmp = WriteableBitmap.Create(size, size, 96, 96, PixelFormats.Bgra32, null, pixels, size * 4); return(bmp); }
private static ImageSource WpfImage(IImage image) { var pinnedArray = GCHandle.Alloc(image.Data, GCHandleType.Pinned); var addr = pinnedArray.AddrOfPinnedObject(); ImageSource bsource = WriteableBitmap.Create(image.Width, image.Height, 96.0, 96.0, PixelFormat(image), null, addr, image.DataLen, image.Stride); GCHandle handle = pinnedArray; return(bsource);/* * return new System.Windows.Controls.Image * { * Source = bsource, * Width = image.Width, * Height = image.Height, * MaxHeight = image.Height, * MaxWidth = image.Width, * Margin = new Thickness(4) * };*/ /* * var mip = image.MipMaps.First(); * { * var mipAddr = addr + mip.DataOffset; * var mipSource = BitmapSource.Create(mip.Width, mip.Height, 96.0, 96.0, * PixelFormat(image), null, mipAddr, mip.DataLen, mip.Stride); * return new System.Windows.Controls.Image * { * Source = mipSource, * Width = mip.Width, * Height = mip.Height, * MaxHeight = mip.Height, * MaxWidth = mip.Width, * Margin = new Thickness(4) * }; * }*/ }