We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I get the byte[] that is the image when editing?

Thread ID:

Created:

Updated:

Platform:

Replies:

148752 Nov 1,2019 10:24 PM UTC Nov 4,2019 02:08 PM UTC Xamarin.Forms 2
loading
Tags: SfImageEditor
Jesse Knott
Asked On November 1, 2019 10:24 PM UTC

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!

Jesse Knott
Replied On November 2, 2019 01:00 AM UTC

Im sorry, I spoke too soon... I had another bug in the render portion of my code. That was causing my problem.
The code I provided work's exactly as expected for saving the image to the DB.

One additional question however, Is there anyway to specify a filename to save to when using the editor.Save() function?

Thanks again!


Vignesh Ramesh [Syncfusion]
Replied On November 4, 2019 02:08 PM UTC

Hi Jesse, 

Greetings from Syncfusion! 

Currently we don’t have support to specify the filename in Save method of SfImageEditor. So, we have considered this as feature request and please find the feedback task below here. 


Please cast your vote to make it count. We will prioritize the features every release based on the demands and we do not have immediate plan to implement this feature since we committed with already planned work. So, this feature will be available any of our upcoming release. 

If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal. 

Regards, 
Vignesh. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon