[UWP]如何使用图像进行操作而不将其加载到可视树中? [英] [UWP] How to manipulate with an image without loading it into the visual tree ?
问题描述
构建`Image`,然后在一个非常宽的行中显示在屏幕上。
BitmapImage是图像处理的错误类。它可以加载和显示图像,但它不能访问像素,因此您无法对其进行操作。由于它唯一有用的是显示它是一个安全的优化,不加载BitmapImage
,直到它可显示。
要访问像素,请将图像加载到WriteableBitmap直接使用WriteableBitmap。 SetSource
(来自BitmapSource:与BitmapImage相同的父级)或使用
BitmapDecoder 。使用哪一个取决于具体情况。如果唯一的目标是操作,那么我可能会使用BitmapDecoder。如果你想进行一些操作然后显示图像,那么我可能会使用WriteableBitmap。
- Rob
BitmapImage is the wrong class for image manipulation. It can load and show the image, but it doesn't give access to the pixels so you can't manipulate it. Since the only thing it's useful for is display it is a safe optimisation not to load the BitmapImage until it is displayable.
For access to the pixels either load your image into a WriteableBitmap directly with WriteableBitmap.SetSource (from BitmapSource: the same parent as BitmapImage) or use a BitmapDecoder. Which one to use depends on the situation. If the only goal is manipulation then I'd probably use the BitmapDecoder. If you want to do a little manipulation in place and then display the image then I'd probably use the WriteableBitmap.
--Rob
这篇关于[UWP]如何使用图像进行操作而不将其加载到可视树中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!