Tag: writablebitmap

WritableBitmap更改后,界面中的图像不会更新

我试图通过每次移动鼠标指针时绘制圆圈来更新图像。 pixelBuffer存储在map对象中,并使用CircleFilledWithGradientMethod()更新。 我将像素缓冲区加载到WriteableBitmap Bitmap ,然后尝试通过将我的XAML UI中的图像元素的图像源设置为WriteableBitmap Bitmap来显示它。 会发生什么,当我第一次移动鼠标时,我看到前两个圆圈被绘制,但是当我移动鼠标时,图像不会更新。 为什么会这样? 有没有一种方法我应该调用Image来强制它重绘? 之所以我使用stream.WriteAsync两次,当我刚刚使用它时,只是为了表明它正常工作。 private async void TextArea_PointerMoved(object sender, PointerRoutedEventArgs e) { Pixel pixel1 = new Pixel(255, 0, 0); Pixel pixel2 = new Pixel(255, 255, 255); map.CircleFilledWithGradient((int) pointer.Position.X, (int)pointer.Position.Y, 100, pixel1, pixel2); using (Stream stream = Bitmap.PixelBuffer.AsStream()) { stream.WriteAsync(map.pixelData, 0, map.pixelData.Length); } map.CircleFilledWithGradient((int)pointer.Position.X+100, (int)pointer.Position.Y, 100, pixel1, pixel2); using […]

如何在windows 10 uwp中有效地使用WriteableBitmap.setpixel()?

我有一个场景 选择一个图像文件然后使用BitmapDecoder将源转换为WriteableBitmap并将image.source设置为WriteableBitmap。 现在,当用户点击图像时,我得到坐标,然后想要用特定颜色为该像素周围的整个区域着色。(就像绘画中的填充选项一样)。 我用的代码是 private void setPixelColors(int xCord, int yCord, int newColor) { Color color = bit.GetPixel(xCord, yCord); if (color.R <= 5 && color.G <= 5 && color.B <= 5 || newColor == ConvertColorToInt(color)) { //Debug.WriteLine("The color was black or same returning"); return; } setPixelColors(xCord + 1, yCord, newColor); setPixelColors(xCord, yCord + 1, newColor); setPixelColors(xCord […]

从BitmapSource复制到WritableBitmap

我试图将BitmapSource的一部分复制到WritableBitmap。 到目前为止这是我的代码: var bmp = image.Source as BitmapSource; var row = new WriteableBitmap(bmp.PixelWidth, bottom – top, bmp.DpiX, bmp.DpiY, bmp.Format, bmp.Palette); row.Lock(); bmp.CopyPixels(new Int32Rect(top, 0, bmp.PixelWidth, bottom – top), row.BackBuffer, row.PixelHeight * row.BackBufferStride, row.BackBufferStride); row.AddDirtyRect(new Int32Rect(0, 0, row.PixelWidth, row.PixelHeight)); row.Unlock(); 我得到“ArgumentException:值不在预期的范围内。” 在CopyPixels行中。 我尝试用row.PixelHeight * row.PixelWidth交换row.PixelHeight * row.BackBufferStride ,但后来我得到一个错误,说该值太低了。 我找不到使用CopyPixels这个重载的单个代码示例,所以我正在寻求帮助。 谢谢!