簡體   English   中英

C#WPF加載圖像時,寬度和高度被切換

[英]C# WPF when image is loaded the width and height are switched

在WPF c#中,在運行時從代碼加載圖像時,當切換寬度和高度時,一些圖像正在加載,因此width = height和height = width使得圖像旋轉了90度。 在文件系統屬性選項卡中,寬度和高度正確,並且圖像顯示正確。 如果我在任何imageViewer中打開此圖像,則圖像會正確顯示,但如果在Powerpoint中打開,則會發現相同的問題,並且圖像已打開。 我在WPF中下載了一些其他代碼,所有代碼都顯示了圖像已翻轉。 大多數圖像顯示正確。

例如,此圖像: https : //www.dropbox.com/s/5fki0ew3gt78myi/TestImage_Widht4000_Height6000.JPG?dl=0

Widht = 4000和Height = 6000,但是如果我得到了位圖.PixelWidth = 6000和bitmap.PixelHeight = 400

誰能幫忙! 謝謝

我已經嘗試了一切:(

           var ImagefilePath = SelectedImagePath + "\\" + ((object[])(e.AddedItems))[0].ToString();

            BitmapImage bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = new Uri(ImagefilePath.ToString(), UriKind.Absolute);

            bitmap.EndInit();

            // Set Image.Source  
            imgPhoto.Source = bitmap;

            ImageInfoText.Content=" W=" + bitmap.PixelWidth + " H=" + bitmap.PixelHeight;

它很可能是圖像本身中的元數據。 您需要擺脫元數據,這應該可以解決您的問題。

這是一個類似的問題: WPF加載某些圖像時會旋轉

這是刪除元數據的方法: 清除圖像中元數據的簡便方法?

最好的方法是使用System.Windows.Media.Imaging.BitmapEncoder類的Metadata集合屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM