我应该使用什么WPF图像类型来执行多个转换

时间:2022-09-10 23:44:17

I need to perform multiple operations on an Image, for example, I need to resize the image, perhaps pad it to maintain aspect ratio (and draw a background color), and conditionally stamp with a watermark.

我需要对一个Image执行多个操作,例如,我需要调整图像大小,可能会将其填充以保持纵横比(并绘制背景颜色),并有条件地标记水印。

I'm currently using BitmapFrame as the type that I pass between the methods involved.

我目前正在使用BitmapFrame作为我在所涉及的方法之间传递的类型。

Can anyone recommend another type which I should use to perform incremental updates on images?

任何人都可以推荐另一种类型,我应该用它来执行图像的增量更新?

I could possibly create a composition of various images, although I'm not sure which types I should use for this?

我可以创建各种图像的组合,虽然我不确定我应该使用哪种类型的图像?

2 个解决方案

#1


9  

WriteableBitmap is suitable when you want to make incremental updates of the image. Both BitmapFrame and WriteableBitmap inherit from BitmapSource, and WriteableBitmap can be instantiated using any BitmapSource.

当您想要对图像进行增量更新时,WriteableBitmap非常适合。 BitmapFrame和WriteableBitmap都继承自BitmapSource,而WriteableBitmap可以使用任何BitmapSource实例化。

You might also want to have a look at the WriteableBitmapEx library that provides a wealth of efficient WriteableBitmap extension methods for bitmap manipulation. This library is applicable to WPF applications as well as Silverlight, WP7 and Metro.

您可能还想查看WriteableBitmapEx库,该库为位图操作提供了大量高效的WriteableBitmap扩展方法。该库适用于WPF应用程序以及Silverlight,WP7和Metro。

#2


6  

Try WriteableBitmap

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx

Use the WriteableBitmap class to update and render a bitmap on a per-frame basis. This is useful for generating algorithmic content, such as a fractal image, and for data visualization, such as a music visualizer.

使用WriteableBitmap类以每帧为基础更新和呈现位图。这对于生成算法内容(例如分形图像)和数据可视化(例如音乐可视化器)非常有用。

For greater control over updates, and for multi-threaded access to the back buffer, use the following workflow.

要更好地控制更新,以及对后台缓冲区进行多线程访问,请使用以下工作流程。

1. Call the Lock method to reserve the back buffer for updates.

1.调用Lock方法以保留后台缓冲区以进行更新。

2. Obtain a pointer to the back buffer by accessing the BackBuffer property.

2.通过访问BackBuffer属性获取指向后台缓冲区的指针。

3. Write changes to the back buffer. Other threads may write changes to the back buffer when the WriteableBitmap is locked.

3.将更改写入后台缓冲区。当WriteableBitmap被锁定时,其他线程可能会对后缓冲区写入更改。

4. Call the AddDirtyRect method to indicate areas that have changed.

4.调用AddDirtyRect方法以指示已更改的区域。

5. Call the Unlock method to release the back buffer and allow presentation to the screen.

5.调用Unlock方法释放后缓冲区并允许显示到屏幕。

When updates are sent to the rendering thread, the rendering thread copies the changed rectangles from the back buffer to the front buffer. The rendering system controls this exchange to avoid deadlocks and redraw artifacts, such as "tearing".

当更新发送到呈现线程时,呈现线程将更改的矩形从后缓冲区复制到前台缓冲区。渲染系统控制此交换以避免死锁和重绘伪像,例如“撕裂”。

#1


9  

WriteableBitmap is suitable when you want to make incremental updates of the image. Both BitmapFrame and WriteableBitmap inherit from BitmapSource, and WriteableBitmap can be instantiated using any BitmapSource.

当您想要对图像进行增量更新时,WriteableBitmap非常适合。 BitmapFrame和WriteableBitmap都继承自BitmapSource,而WriteableBitmap可以使用任何BitmapSource实例化。

You might also want to have a look at the WriteableBitmapEx library that provides a wealth of efficient WriteableBitmap extension methods for bitmap manipulation. This library is applicable to WPF applications as well as Silverlight, WP7 and Metro.

您可能还想查看WriteableBitmapEx库,该库为位图操作提供了大量高效的WriteableBitmap扩展方法。该库适用于WPF应用程序以及Silverlight,WP7和Metro。

#2


6  

Try WriteableBitmap

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx

Use the WriteableBitmap class to update and render a bitmap on a per-frame basis. This is useful for generating algorithmic content, such as a fractal image, and for data visualization, such as a music visualizer.

使用WriteableBitmap类以每帧为基础更新和呈现位图。这对于生成算法内容(例如分形图像)和数据可视化(例如音乐可视化器)非常有用。

For greater control over updates, and for multi-threaded access to the back buffer, use the following workflow.

要更好地控制更新,以及对后台缓冲区进行多线程访问,请使用以下工作流程。

1. Call the Lock method to reserve the back buffer for updates.

1.调用Lock方法以保留后台缓冲区以进行更新。

2. Obtain a pointer to the back buffer by accessing the BackBuffer property.

2.通过访问BackBuffer属性获取指向后台缓冲区的指针。

3. Write changes to the back buffer. Other threads may write changes to the back buffer when the WriteableBitmap is locked.

3.将更改写入后台缓冲区。当WriteableBitmap被锁定时,其他线程可能会对后缓冲区写入更改。

4. Call the AddDirtyRect method to indicate areas that have changed.

4.调用AddDirtyRect方法以指示已更改的区域。

5. Call the Unlock method to release the back buffer and allow presentation to the screen.

5.调用Unlock方法释放后缓冲区并允许显示到屏幕。

When updates are sent to the rendering thread, the rendering thread copies the changed rectangles from the back buffer to the front buffer. The rendering system controls this exchange to avoid deadlocks and redraw artifacts, such as "tearing".

当更新发送到呈现线程时,呈现线程将更改的矩形从后缓冲区复制到前台缓冲区。渲染系统控制此交换以避免死锁和重绘伪像,例如“撕裂”。