Xamarin.forms 表单:如何获取流&;最终裁剪图像的路径值?
我正在使用从相机和多媒体资料中选择的图像进行裁剪 我的代码:Xamarin.forms 表单:如何获取流&;最终裁剪图像的路径值?,xamarin.forms,path,stream,Xamarin.forms,Path,Stream,我正在使用从相机和多媒体资料中选择的图像进行裁剪 我的代码: async void OpenCamera() { try { await CrossMedia.Current.Initialize(); //I need to open camera only here, no need of a pop up again. new ImageCropper()
async void OpenCamera()
{
try
{
await CrossMedia.Current.Initialize();
//I need to open camera only here, no need of a pop up again.
new ImageCropper()
{
PageTitle = "Test Title",
AspectRatioX = 1,
AspectRatioY = 1,
CropShape = ImageCropper.CropShapeType.Rectangle,
SelectSourceTitle = "Select source",
TakePhotoTitle = "Take Photo",
PhotoLibraryTitle = "Photo Library",
Success = (imageFile) =>
{
Device.BeginInvokeOnMainThread(() =>
{
profilephoto.Source = ImageSource.FromFile(imageFile);
});
}
}.Show(this);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("CameraException:>" + ex);
}
}
async void Opengallery()
{
try
{
await CrossMedia.Current.Initialize();
//I need to open gallery only here, no need of a pop up again.
new ImageCropper()
{
PageTitle = "Test Title",
AspectRatioX = 1,
AspectRatioY = 1,
CropShape = ImageCropper.CropShapeType.Rectangle,
SelectSourceTitle = "Select source",
TakePhotoTitle = "Take Photo",
PhotoLibraryTitle = "Photo Library",
Success = (imageFile) =>
{
Device.BeginInvokeOnMainThread(() =>
{
profilephoto.Source = ImageSource.FromFile(imageFile);
//var stream = ImageSource.FromFile(imageFile);
//imagefile = imageFile;
});
}
}.Show(this);
}
}
//Save image to gallery
private MediaFile _mediaFile;
public async void SaveProfile(object sender, EventArgs args)
{
var content = new MultipartFormDataContent();
content.Add(new StreamContent(_mediaFile.GetStream()), "\"file\"", $"\"{_mediaFile.Path}\"");
HttpClient client = new HttpClient();
var response = client.PostAsync(new Uri("Service URL"), content).Result;
}
我需要将裁剪后的图像保存到服务器,我在最初的实现中使用了该插件,并使用该插件将所选图像作为媒体文件。使用MediaFile,我可以使用下面的流和路径将图片保存到服务器
但是在裁剪实现之后,我不知道如何获得最终裁剪图像的流值和路径。因此,请为这个问题提出一个解决方案SaveProfile
是OpenCamera()
和Opengallery()
之外的另一个函数,如中所示,使用Success
处理程序
new ImageCropper()
{
Success = (imageFile) =>
{
// image file is the string path, do whatever you
// need here
var stream = File.Open(imageFile);
}
}.Show(this);
其中,imageFile
是包含文件路径的字符串,如中所示,请使用Success
处理程序
new ImageCropper()
{
Success = (imageFile) =>
{
// image file is the string path, do whatever you
// need here
var stream = File.Open(imageFile);
}
}.Show(this);
其中imageFile
是一个包含文件路径的字符串您可以使用该插件
Success=(图像文件)=>
{
CrossFileUploader.Current.UploadFileAsync(“),new FilePathItem(“,”),new Dictionary()
{
{"" , ""}
}
);
}
您可以使用该插件
Success=(图像文件)=>
{
CrossFileUploader.Current.UploadFileAsync(“),new FilePathItem(“,”),new Dictionary()
{
{"" , ""}
}
);
}
请避免在不必要的时候在标题中添加标签。请避免在不必要的时候在标题中添加标签。您能解释一下吗?我还需要流值。还有许多现有问题解释了如何使用文件路径创建流。请参见扩展示例您建议的编辑显示您实际上想要的是字节数组,而不是流。如果这是您所需要的,ImageCropper有一个助手来做这件事。看文件:你能再解释一下吗?我还需要流值。还有许多现有问题解释了如何使用文件路径创建流。请参见扩展示例您建议的编辑显示您实际上想要的是字节数组,而不是流。如果这是您所需要的,ImageCropper有一个助手来做这件事。见文件: