如何在C#WinRTwinmd中调整图像大小?

如何在C#WinRTwinmd中调整图像大小?,第1张

如何在C#WinRT / winmd中调整图像大小?

从此处获取的如何缩放裁剪示例

async private void BitmapTransformTest(){    // hard pred image location    string filePath = "C:\Users\Public\Pictures\Sample Pictures\fantasy-dragons-wallpaper.jpg";    StorageFile file = await StorageFile.GetFileFromPathAsync(filePath);    if (file == null)        return;    // create a stream from the file and depre the image    var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);    BitmapDeprer deprer = await BitmapDeprer.CreateAsync(fileStream);    // create a new stream and enprer for the new image    InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();    BitmapEnprer enc = await BitmapEnprer.CreateForTranscodingAsync(ras, deprer);    // convert the entire bitmap to a 100px by 100px bitmap    enc.BitmapTransform.ScaledHeight = 100;    enc.BitmapTransform.ScaledWidth = 100;    BitmapBounds bounds = new BitmapBounds();    bounds.Height = 50;    bounds.Width = 50;    bounds.X = 50;    bounds.Y = 50;    enc.BitmapTransform.Bounds = bounds;    // write out to the stream    try    {        await enc.FlushAsync();    }    catch (Exception ex)    {        string s = ex.ToString();    }    // render the stream to the screen    BitmapImage bImg = new BitmapImage();    bImg.SetSource(ras);    img.Source = bImg; // image element in xaml}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5499046.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存