简体   繁体   English

C#WPF加载图像时,宽度和高度被切换

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

In WPF c# loading an image from code in runtime, some images are loading when the width and height are switched so the width=height and height=width so the image is turned in 90 degrees. 在WPF c#中,在运行时从代码加载图像时,当切换宽度和高度时,一些图像正在加载,因此width = height和height = width使得图像旋转了90度。 In the file system properties tab, the Width and Height are correct and the image is shown correctly. 在文件系统属性选项卡中,宽度和高度正确,并且图像显示正确。 If I open this image in any imageViewer the image is shown correctly but if I open it in powerpoint the same issue is found and the image is turned. 如果我在任何imageViewer中打开此图像,则图像会正确显示,但如果在Powerpoint中打开,则会发现相同的问题,并且图像已打开。 I downloaded some other codes in WPF and all are showing the image turned. 我在WPF中下载了一些其他代码,所有代码都显示了图像已翻转。 most images are shown correctly. 大多数图像显示正确。

For example This Image : https://www.dropbox.com/s/5fki0ew3gt78myi/TestImage_Widht4000_Height6000.JPG?dl=0 例如,此图像: https : //www.dropbox.com/s/5fki0ew3gt78myi/TestImage_Widht4000_Height6000.JPG?dl=0

The Widht=4000and Height=6000 but if I get the bitmap.PixelWidth=6000 and bitmap.PixelHeight=400 Widht = 4000和Height = 6000,但是如果我得到了位图.PixelWidth = 6000和bitmap.PixelHeight = 400

Can anyone please help! 谁能帮忙! Thanks 谢谢

I have tried everything :( 我已经尝试了一切:(

           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;

It is most probably the metadata within the image itself. 它很可能是图像本身中的元数据。 You need to get rid of the metadata and that should fix your problem. 您需要摆脱元数据,这应该可以解决您的问题。

Here is a similar issue : WPF some images are rotated when loaded 这是一个类似的问题: WPF加载某些图像时会旋转

Here is how you can remove metadata: Easy way to clean metadata from an image? 这是删除元数据的方法: 清除图像中元数据的简便方法?

The preferable way would be to use the System.Windows.Media.Imaging.BitmapEncoder class's Metadata collection property. 最好的方法是使用System.Windows.Media.Imaging.BitmapEncoder类的Metadata集合属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM