Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
Resizing a PNG in a UWP project without losing transparency?
Ali Roshanbin
Jan 18 2017 6:05 AM
244
Reply
Hi there,
I want to resize a PNG image that is transparent in a Universal Windows Project, but I lose transparency.
Similar to this article of the Stack Overflow website.
http://stackoverflow.com/questions/753968/why-does-resizing-a-png-image-lose-transparency
Can anyone help me to figure it out?
public static async Task<BitmapImage> ResizedImage(StorageFile ImageFile, int maxWidth, int maxHeight)
{
IRandomAccessStream inputstream = await ImageFile.OpenReadAsync();
BitmapImage sourceImage = new BitmapImage();
sourceImage.SetSource(inputstream);
var origHeight = sourceImage.PixelHeight;
var origWidth = sourceImage.PixelWidth;
var ratioX = maxWidth / (float)origWidth;
var ratioY = maxHeight / (float)origHeight;
var ratio = Math.Min(ratioX, ratioY);
var newHeight = (int)(origHeight * ratio);
var newWidth = (int)(origWidth * ratio);
sourceImage.DecodePixelWidth = newWidth;
sourceImage.DecodePixelHeight = newHeight;
return sourceImage;
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to caluclate the amount based labels values Count
How to rename a file when it is already exist in a folder ?