Hello,
In my application I store images in the database table using a Blob record.
I have tried the following code, but it's not having the expected results.
Within
my CS code, I have the SfImageEditor object named `editor` I have
edited the handler for the ImageSaving `editor_ImageSaving`
Stream str = await editor.GetStream();
byte[] bytes = new byte[(int)str.Length];
str.WriteAsync(bytes, 0, (int)str.Length);
viewModel.photo.Image = bytes;
viewModel.photoRep.AddOrUpdate(viewModel.photo);
My viewmodel is as follows.
public class ImageModel
{
public PhotosRepository photoRep => new PhotosRepository();
public Photos photo { get; set; }
public ImageSource Image { get; set; }
public ImageModel(Photos incoming)
{
photo = incoming;
Assembly assembly = typeof(ImageModel).GetTypeInfo().Assembly;
Image = ImageSource.FromStream(() => new MemoryStream(photo.Image));
}
}
and finally my cusom photos class....
private int id;
private int flags;
private int recordType;
private int recordCategory;
private int parentrecord;
private byte[] image;
private string path;
private string file;
private ObservableCollection<Photos> oc = new ObservableCollection<Photos>();
/// <summary>
/// Gets or sets pK for the photo being stored in the DB.
/// </summary>
[PrimaryKey]
[AutoIncrement]
public int Id
{
get => id;
set
{
SetProperty(ref id, value, nameof(Id));
OnPropertyChanged(nameof(Id));
}
}
....... etc etc etc
I
am trying to load the image into the editor, allow the user to rotate,
crop, or mark up the image, then return to image bytes so I can save
them in the database.
Using the code
above, I can load the image, and edit it, when I step through the code it
appears to be working, but the image becomes corrupt and cannot be
re-read from the database. I've also seen that the image goes from being approx 32kb up to 80kb when returned from the GetStream() I suspect that this is not the image bytes, but perhaps the image+JSON?
Can you share a sample of how to get the image bytes? or what method I can use to return the newly modified image to the database?
Thanks!