- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些 WriteableBitmap 对象。假设实际上位于 WriteableBitmap 对象上的图像是 600x400。
我想复制部分图像 - 一些矩形(例如 WriteableBitmap 中间的 100x100 矩形)并将副本粘贴到其他图像控件。
我该怎么做?
最佳答案
我怀疑你现在已经解决了这个问题,但我遇到了同样的问题并且我找到了答案所以我想我应该发布它。 http://writeablebitmapex.codeplex.com/ 处的代码有一个“裁剪”例程,几乎可以满足您的需求。一旦将 SizeOfArgb 常量设置为 4,就可以使用它:
public static WriteableBitmap Crop(this WriteableBitmap bmp, int x, int y, int width, int height)
{
var srcWidth = bmp.PixelWidth;
var srcHeight = bmp.PixelHeight;
// If the rectangle is completly out of the bitmap
if (x > srcWidth || y > srcHeight)
{
return new WriteableBitmap(0, 0);
}
// Clamp to boundaries
if (x < 0) x = 0;
if (x + width > srcWidth) width = srcWidth - x;
if (y < 0) y = 0;
if (y + height > srcHeight) height = srcHeight - y;
// Copy the pixels line by line using fast BlockCopy
var result = new WriteableBitmap(width, height);
for (var line = 0; line < height; line++)
{
var srcOff = ((y + line) * srcWidth + x) * SizeOfArgb;
var dstOff = line * width * SizeOfArgb;
Buffer.BlockCopy(bmp.Pixels, srcOff, result.Pixels, dstOff, width * SizeOfArgb);
}
return result;
}
关于silverlight - 如何复制 WriteableBitmap 的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6096822/
我想弄清楚如何释放 WriteableBitmap 内存。 在下一段代码中,我用来自“BigImage”(3600 * 4800 px,仅用于测试)的大量数据填充 WriteableBitmap 的后
我可以像这样成功加载以下位图并将其显示在 View 上的图像控件中。 var bitmapImage = new BitmapImage {
我目前有一个这样的循环: foreach(var item in theList) { //create writeablebitmap from item.GetPicture() which re
我正在将分形作为一个私有(private)项目来练习(离开初学者水平^^)。我有一个包含图像的 Canvas ,该图像绑定(bind)到 WriteableBitmap: 我的 View 模
问题来了。我想从本地驱动器打开一个文件,然后将它变成一个 WritableBitmap 以便我可以编辑它。但问题是,我无法从 Uri 或类似的东西创建 WritableBitmap。我也知道如何将文件
我正在用 WPF (C#) 编写一个应用程序,它对位图集合执行长时间操作。为了让我的应用程序保持响应,我决定使用另一个线程来执行位图操作并在主 UI 线程的进度条上报告进度。我原以为 Backgrou
我有一个 WritableBitmap,它在单独的线程上更新,特别是响应事件。 myWritableBitmap.Lock(); CopyMemory(myWritableBitmap.BackBuf
我正在 WP7 芒果中编写应用程序,并尝试将从绑定(bind)加载的图像转换为 XAML 中的 WriteableBitmap,例如:
我正在使用下面的代码创建一个基于 UI 元素的动态磁贴。它在 WriteableBitmap 上呈现 uiElement,保存位图 + 返回文件名。此方法在 Windows Phone 后台任务代理中
有一个简单的MSDN example关于可写位图。 它展示了如何通过在按下鼠标并在 WPF 图像控件上移动时仅更新一个像素来使用光标绘制手绘线。 writeableBitmap.Lock();
我创建了一个 Gray16 格式的 WriteableBitmap。我想将此 WriteableBitmap 调整为我已知的尺寸,保留像素格式(Gray16)。 有人致力于调整 WriteableBi
我有一些 WriteableBitmap 对象。假设实际上位于 WriteableBitmap 对象上的图像是 600x400。 我想复制部分图像 - 一些矩形(例如 WriteableBitmap
有没有办法将 WriteableBitmap 转换为字节数组?如果有办法从中获取可写位图,我也将其分配给 System.Windows.Controls.Image 源。我试过这个但是在 FromHB
我正在使用 PhotoChooserTask 从图库中挑选图像,这是我的设置 private void ApplicationBarIconButton_Click(object sender, Ev
我有一个应用程序,其中使用 WriteableBitmap 进行对性能敏感的绘图。使用 CompositionTarget.Rendering 调用一个事件来实际更新 WriteableBitmap
我已经尝试了几个小时,但我无法解决这个问题。 我有一个 UserControl,它是 800x369,它只包含一条形成世界地图的路径。我将其放在横向页面上,然后将其呈现为 WriteableBitma
我正在修改 ColorBasic Kinect 示例,以便显示覆盖到视频流的图像。所以我所做的是加载一个图像具有透明背景(现在是一个 GIF,但它可能会改变),并写入显示的位图。 我得到的错误是我正在
目标是渲染 2 行以 ... 结尾的文本。我认为问题是高度不会按照我告诉它的大小呈现(参见 maxHeight=30,但 actualHeight 82)。 “canvas”变量是一个可写的位图。 我
我在连接到图像控件的 Windows Phone 8 应用程序中有一个 WriteableBitmap。我循环遍历图像的每一行并一次异步绘制一行像素,然后安排下一行进行绘制。但是,更改基础像素数据似乎
我正在开发一个用于将图像上传到网络服务器的 Windows Phone 应用程序。我正在从我的设备中选择所有图像到一个列表对象。我正在将所有位图图像一张一张地转换为 byte[]。 我的代码 publ
我是一名优秀的程序员,十分优秀!