[UWP]如何使用图像进行操作而不将其加载到可视树中? [英] [UWP] How to manipulate with an image without loading it into the visual tree ?

查看:70
本文介绍了[UWP]如何使用图像进行操作而不将其加载到可视树中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常宽的png图像,它被分成几行(因为png的宽度限制为Int16.MaxValue)。在Silverlight中,我将图像设置为BitmapImage,然后将行提取到WriteableBitmap中。然后为每个
构建`Image`,然后在一个非常宽的行中显示在屏幕上

解决方案

BitmapImage是图像处理的错误类。它可以加载和显示图像,但它不能访问像素,因此您无法对其进行操作。由于它唯一有用的是显示它是一个安全的优化,不加载BitmapImage
,直到它可显示。


要访问像素,请将图像加载到WriteableBitmap直接使用WriteableBitmap。 SetSource 
(来自BitmapSource:与BitmapImage相同的父级)或使用
BitmapDecoder
。使用哪一个取决于具体情况。如果唯一的目标是操作,那么我可能会使用BitmapDecoder。如果你想进行一些操作然后显示图像,那么我可能会使用WriteableBitmap。


- Rob



I have a very wide png image which is split to a few rows (because png has width limit to Int16.MaxValue). In Silverlight I would set the image to a BitmapImage then extract rows into WriteableBitmap each. Then construct `Image` for each and then show on the screen in one very wide row.

解决方案

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆