Check the width and height of an image

后端 未结 3 1762
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 10:10

I am able to display the picture in the picture box without checking the file size by the following code:

private void button3_Click_1(object sender, EventAr         


        
3条回答
  •  囚心锁ツ
    2021-01-17 10:23

    UWP has currently a nice interface to obtain image properties.

            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");
    
            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                // Application now has read/write access to the picked file
                ImageProperties IP = await file.Properties.GetImagePropertiesAsync();
    
                double Width = IP.Width;
                double Height = IP.Height;
            }
    

提交回复
热议问题