【问题标题】:Give a name to a writeable bitmap为可写位图命名
【发布时间】:2015-10-12 20:59:18
【问题描述】:

我想知道是否有任何方法可以为 writeableBitmap 命名

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

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);
                }
            }

我通过在 AlGridView.DataContext = images 中绑定数据将它们添加到 gridView;

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

在转换它们之前,如您在上面看到的,我有一个名称(即 1.png、2.png 等),但是一旦它们是可写位图,我还没有找到任何方法来命名/获取名称他们

和

bitmap.SetVale(Name, f.Name);

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

有什么想法吗?

【问题讨论】:

    标签: c# gridview bitmap windows-phone-8.1 filenames


    【解决方案1】:

    哈!我想我已经找到了解决方案:

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

    谢谢大家!

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多