给一个可写位图命名

本文关键字:位图 一个 | 更新日期: 2023-09-27 18:17:25

我想知道是否有办法给writeableBitmap一个名字

我的文件夹里有3张图片。为了在gridView中显示它们,我将它们转换为writtieablebitmap

if (file.Count > 0)
        {
            var images = new List<WriteableBitmap>();
            foreach (StorageFile f in file)
            {
                var name = f.Name;
                Debug.WriteLine(f.Name);
                ImageProperties properties = await f.Properties.GetImagePropertiesAsync();
                if (properties.Width > 0)
                {
                    var bitmap = new WriteableBitmap((int)properties.Width, (int)properties.Height);
                    Debug.WriteLine(bitmap.PixelWidth);
                    using (var stream = await f.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        bitmap.SetSource(stream);
                    }
                    images.Add(bitmap);
                    Debug.WriteLine(images.Count);
                }
            }

我将它们添加到gridView通过绑定数据在AlGridView。

现在,一旦我与这些图像交互,我按下一个按钮,我需要保存选择…但是使用数字数组[1,2,3]

在转换它们之前,正如你在上面看到的,我有一个名字(1.png, 2.png等),但是一旦它们是writablebitmap,我就没有找到任何方法来给它们一个名字

bitmap.SetVale(Name, f.Name);

不起作用,因为它说它不能将字符串转换为DependencyProperty

任何想法?

给一个可写位图命名

哈!我想我已经找到解决办法了:

properties.Title = name;
var bitmap = new WriteableBitmap((int)properties.Width, (int)properties.Height);
bitmap.SetValue(NameProperty, (string)properties.Title);

谢谢大家!