private void BoxBlurVertical(WritableBitmap bmp, int range) { int w = bmp.PixelWidth, h = bmp.PixelHeight, halfRange = range / 2, oldPixelOffset = -(halfRange + 1) * w, newPixelOffset = (halfRange) * w; int[] newColors = new int[h]; for (int x = 0; x < w; x++) { int hits = 0, r = 0, g = 0, b = 0, index = -halfRange * w + x; for (int y = -halfRange; y < h; y++) { int oldPixel = y - halfRange - 1; if (oldPixel >= 0) { int col = _pixels[index + oldPixelOffset]; if (col != 0) { r -= ((byte)(col >> 16)); g -= ((byte)(col >> 8)); b -= ((byte)col); } hits--; } int newPixel = y + halfRange; if (newPixel < h) { int col = _pixels[index + newPixelOffset]; if (col != 0) { r += ((byte)(col >> 16)); g += ((byte)(col >> 8)); b += ((byte)col); } hits++; } if (y >= 0) { int color = (255 << 24) | ((byte)(r / hits) << 16) | ((byte)(g / hits) << 8) | ((byte)(b / hits)); newColors[y] = color; } index += w; } for (int y = 0; y < h; y++) { PutPixelPtr(y * w + x, newColors[y]); } } }
public void WritableBitmapShouldBeUsable(PixelFormat fmt) { var writableBitmap = new WritableBitmap(256, 256, fmt); var data = new int[256 * 256]; for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { data[y * 256 + x] = (int)((uint)(x + (y << 8)) | 0xFF000000u); } } using (var l = writableBitmap.Lock()) { for (var r = 0; r < 256; r++) { Marshal.Copy(data, r * 256, new IntPtr(l.Address.ToInt64() + r * l.RowBytes), 256); } } var name = nameof(WritableBitmapShouldBeUsable) + "_" + fmt; writableBitmap.Save(System.IO.Path.Combine(OutputPath, name + ".out.png")); CompareImages(name); }
public MandelBrotModel(Action invalidate) { _invalidate = invalidate; ResetCommand = new DelegateCommand(Reset); ZoomInCommand = new DelegateCommand(ZoomIn); ZoomOutCommand = new DelegateCommand(ZoomOut); CenterCommand = new DelegateCommand(Center); RectZoomCommand = new DelegateCommand(RectZoom); Bitmap = new WritableBitmap(_resX, _resY, PixelFormat.Bgra8888); Overlay = new WritableBitmap(_resX, _resY, PixelFormat.Bgra8888); FilterValue = 50; BlurValue = 3; FreqRed = 0.0015; PhaseRed = 0; FreqGreen = 0.0015; PhaseGreen = 1; FreqBlue = 0.0015; PhaseBlue = 0; _addX = -1.2395; _addY = 0.1; _pixels = new int[_resX * _resY]; _zoomFactor = 64; _details = FilterValue + _zoomFactor * 2; _refresh = true; }
private void BoxBlurHorizontal(WritableBitmap bmp, int range) { int w = bmp.PixelWidth, h = bmp.PixelHeight, halfRange = range / 2, index = 0; int[] newColors = new int[w]; for (int y = 0; y < h; y++) { int hits = 0, r = 0, g = 0, b = 0; for (int x = -halfRange; x < w; x++) { int oldPixel = x - halfRange - 1; if (oldPixel >= 0) { int col = _pixels[index + oldPixel]; if (col != 0) { r -= ((byte)(col >> 16)); g -= ((byte)(col >> 8)); b -= ((byte)col); } hits--; } int newPixel = x + halfRange; if (newPixel < w) { int col = _pixels[index + newPixel]; if (col != 0) { r += ((byte)(col >> 16)); g += ((byte)(col >> 8)); b += ((byte)col); } hits++; } if (x >= 0) { int color = (255 << 24) | ((byte)(r / hits) << 16) | ((byte)(g / hits) << 8) | ((byte)(b / hits)); newColors[x] = color; } } for (int x = 0; x < w; x++) { PutPixelPtr(index + x, newColors[x]); } index += w; } }
public SnowViewModel(Action invalidate) { _invalidate = invalidate; ResetCommand = new DelegateCommand(Reset); // Bgra8888 is device-native and much faster. Bitmap = new WritableBitmap(640, 480, PixelFormat.Bgra8888); Reset(); Task.Run(() => MoveFlakes()); }
// 非公開静的メソッド // 公開静的メソッド /// <summary> /// System.Windows.Media.ImageSource を生成します。 /// </summary> /// <param name="image"></param> /// <returns></returns> public static ImageSource CreateImageSource(this Image image) { using (var memoryStream = new MemoryStream()) { image.Save(memoryStream, ImageFormat.Png); memoryStream.Seek(0, SeekOrigin.Begin); var bitmapDecoder = BitmapDecoder.Create( memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); var writable = new WritableBitmap(bitmapDecoder.Frames.Single()); writable.Freeze(); return(writable); } }
public MainPage() { this.InitializeComponent(); this.currentPressedKeys = new HashSet <Key>(); this.displayRefreshTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1000 / 24) }; this.displayRefreshTimer.Tick += (s, e) => this.RefreshDisplay(); this.displayBitmap = new WritableBitmap(160, 120, PixelFormat.Rgba8888); this.ClearDisplay(); this.ScreenImage.Source = this.displayBitmap; this.StartButton.IsEnabled = true; this.StopButton.IsEnabled = false; this.BreakButton.IsEnabled = false; this.ContinueButton.IsEnabled = false; this.StepButton.IsEnabled = false; this.RefreshButton.IsEnabled = false; }
public override void Render(DrawingContext context) { if (_lastFrame != null) { var fmt = (PixelFormat)_lastFrame.Format; if (_bitmap == null || _bitmap.PixelWidth != _lastFrame.Width || _bitmap.PixelHeight != _lastFrame.Height) { _bitmap = new WritableBitmap(_lastFrame.Width, _lastFrame.Height, fmt); } using (var l = _bitmap.Lock()) { var lineLen = (fmt == PixelFormat.Rgb565 ? 2 : 4) * _lastFrame.Width; for (var y = 0; y < _lastFrame.Height; y++) { Marshal.Copy(_lastFrame.Data, y * _lastFrame.Stride, new IntPtr(l.Address.ToInt64() + l.RowBytes * y), lineLen); } } context.DrawImage(_bitmap, 1, new Rect(0, 0, _bitmap.PixelWidth, _bitmap.PixelHeight), new Rect(Bounds.Size)); } base.Render(context); }
private void BoxBlur(WritableBitmap bmp, int range) { BoxBlurHorizontal(bmp, range); BoxBlurVertical(bmp, range); }
/// /// <param name="bitmap"></param> public Scene(WritableBitmap bitmap){ }