How to resize Image in C# WinRT/winmd?

前端 未结 6 744
执念已碎
执念已碎 2020-11-27 18:54

I\'ve got simple question, but so far I\'ve found no answer: how to resize jpeg image in C# WinRT/WinMD project and save it as new jpeg?

I\'m developing Windows 8 Me

6条回答
  •  孤独总比滥情好
    2020-11-27 19:05

    I just spent the last hour and half trying to figure this one out, I have a byte array that is a JPG and tried the answer given... I could not get it to work so I am putting up a new answer... Hopefully this will help someone else out... I am converting the JPG to 250/250 pixels

    private async Task ByteArrayToBitmapImage(byte[] byteArray)
        {
            BitmapImage image = new BitmapImage();
            using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
            {
                using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0)))
                {
                    writer.WriteBytes((byte[])byteArray);
                    writer.StoreAsync().GetResults();
                }
                image.SetSource(stream);
            }
            image.DecodePixelHeight = 250;
            image.DecodePixelWidth = 250;
    
            return image;            
        }
    

提交回复
热议问题