gpt4 book ai didi

xamarin.forms - Xamarin Forms - 调整相机图片大小

转载 作者:行者123 更新时间:2023-12-04 13:07:06 25 4
gpt4 key购买 nike

有人帮我获取了使用 xamarin forms labs camera 拍照的代码:

picker = DependencyService.Get<IMediaPicker> ();  
task = picker.TakePhotoAsync (new CameraMediaStorageOptions {
DefaultCamera = CameraDevice.Rear,
MaxPixelDimension = 800,

});

img.BackgroundColor = Color.Gray;

Device.StartTimer (TimeSpan.FromMilliseconds (250), () => {
if (task != null) {
if (task.Status == TaskStatus.RanToCompletion) {
Device.BeginInvokeOnMainThread (async () => {
//img.Source = ImageSource.FromStream (() => task.Result.Source);
var fileAccess = Resolver.Resolve<IFileAccess> ();
string imageName = "img_user_" + User.CurrentUser().id + "_" + DateTime.Now.ToString ("yy_MM_dd_HH_mm_ss") + ".jpg";
fileName = imageName;

fileAccess.WriteStream (imageName, task.Result.Source);
fileLocation = fileAccess.FullPath(imageName);

FileStream fileStream = new FileStream(fileAccess.FullPath(imageName), FileMode.Open, System.IO.FileAccess.Read);
imageUrl = (string)test[0]["url"];
img.Source = imageUrl;
});
}

return task.Status != TaskStatus.Canceled
&& task.Status != TaskStatus.Faulted
&& task.Status != TaskStatus.RanToCompletion;
}
return true;
});

它保存了图像,但是拍摄的手机图片的实际尺寸很大,有没有办法调整它的大小。

最佳答案

Xamarin Media Plugin 的更新允许您调整图像大小
https://github.com/jamesmontemagno/MediaPlugin
...除此之外,您需要一个更通用的调整大小选项(比如图像来自网络调用,而不是设备,然后看看:
https://github.com/InquisitorJax/Wibci.Xamarin.Images

关于xamarin.forms - Xamarin Forms - 调整相机图片大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25265686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com