admin管理员组文章数量:1386806
I am using Camera.Maui in a new program to create a customized database. This is my first foray into MAUI. Users can enter data about specific items and link them to an existing image on the device. I want to allow the users to take photos of items and store them on the device and then later create new items in the collection and link to the matching image by entering the photo's file name.
NewImage is an Image control on the content page.
I capture the image as follows:
NewImage.Source = cameraView.GetSnapShot(Camera.MAUI.ImageFormat.PNG);
as well as a filename from an Entry control
In a different function I want to save the image to the device using filename.png so that in the future, the user can create a new item - setting the filename of the item to match filename.jpg.
Then on the screen that lists all the items, clicking on the item displays all of the date --- including displaying the image.
So basically I want to do the following
WriteFile(filename, Image.Source)
Note that I am able to successfully write a file to the appropriate folder I specify but that so far the file has always been 0 bytes.
My code is as follows and it creates the file --- but the files contents are not the png image, but instead "Microsoft.Maui.Controls.StreamingImageSou"
Help!!!
private void TakePhotoButton_Clicked(object sender, EventArgs e)
{
NewImage.Source = cameraView.GetSnapShot(Camera.MAUI.ImageFormat.PNG);
SavePhoto.IsEnabled = true;
FileNameEntry.IsEnabled = true;
}
private async void SavePhotoButton_Clicked(object sender, EventArgs e)
{
if (FileNameEntry.Text == string.Empty)
{
await DisplayAlert("Missing Info", "Enter File Name", "OK");
return;
}
string PhotoFileName = FileNameEntry.Text;
// Save file here
string myPicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
var folderPath = Path.Combine(myPicPath, "CapsnPins");
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
PhotoFileName += ".png";
PhotoFileName = PhotoFileName.ToLower();
string filePath = Path.Combine(folderPath, PhotoFileName);
if (!string.IsNullOrEmpty(folderPath))
{
string photoString = NewImage.Source.ToString();
var bytes = System.Text.Encoding.UTF8.GetBytes(photoString);
await File.WriteAllBytesAsync(filePath, bytes, CancellationToken.None);
}
await DisplayAlert("Saved Photo", "Succssfully saved " + PhotoFileName, "OK");
}
本文标签:
版权声明:本文标题:I am using Camera.MAUI and can take picture and display in an Image using Image.source. How do I save the image as png to use it 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744563440a2612904.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论