如何在 xamarin.forms 中调整图像大小? [英] How to resize images in xamarin.forms?

查看:116
本文介绍了如何在 xamarin.forms 中调整图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 xamarin.forms.我必须从图库中选择图像,然后调整它们的大小,然后将它们上传到服务器上.但我不知道如何以给定的特定尺寸调整所选图像的大小?请更新我如何做到这一点?

I am working on xamarin.forms. I have to select images from gallery and then resize them and then upload them on server. But I don't know how I can resize selected image in a given particular size? Please update me how I can do this?

推荐答案

这可以与流一起使用(如果您使用的是媒体插件 https://github.com/jamesmontemagno/MediaPlugin) 或标准字节数组.

This can be used with a stream (if you're using the Media Plugin https://github.com/jamesmontemagno/MediaPlugin) or standard byte arrays.

// If you already have the byte[]
byte[] resizedImage = await CrossImageResizer.Current.ResizeImageWithAspectRatioAsync(originalImageBytes, 500, 1000);

// If you have a stream, such as:
// var file = await CrossMedia.Current.PickPhotoAsync(options);
// var originalImageStream = file.GetStream();
byte[] resizedImage = await CrossImageResizer.Current.ResizeImageWithAspectRatioAsync(originalImageStream, 500, 1000);

这篇关于如何在 xamarin.forms 中调整图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆