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. Image for the cookie policy date

Resize image before sending it to the server using an API

Hey!

I have an app (Android & iOS) with a camera function. With this function, the user can simply click on a button to open te camera app, take a picture and this picture is then send to the server with an API:


Now I have a new camera function with an in-app camera (so that the camera app isn't needed anymore). Now the user can take a picture, which is then showed in Syncfusion image editor (rotation and cropping). This image should then be send to the API:


Now I have the following problem: the picture size is too big and the system rejects pictures which are too big.
You can see in the first image that I resize the picture to medium so that the system can handle the image. If I don't do this, the image will simply not be send to the server. Problem is that I have no idea how to do this resizing in the Image Editor.

Anyone that can help?

Best regards,
Ganesh


8 Replies

SS Sridevi Sivakumar Syncfusion Team December 9, 2020 11:59 AM UTC

Hi Ganesh Gebhard,

Greetings from Syncfusion.

From your update, you are loading the saved image stream to the server API and before that, you have to resize the image, which is loaded in the SfImageEditor then, please use the below KB

https://www.syncfusion.com/kb/9400/how-to-resize-the-image-with-imageeditor

Query: the picture size is too big and the system rejects pictures which are too big.

This update is mainly to get the confirmation of your reported issue to proceed with this without any misleading.

Are you facing any problem on loading the large size image to SfImageEditor if then could you please share us with a screenshot with used device configuration?

Are you faced any crash issues while loading large-size image?

Are you saving the image with jpg format since by default file size will be compressed while saving with jpg format?

Regards,
Sridevi S.
 
 



GG Ganesh Gebhard December 9, 2020 01:22 PM UTC

Hi Sridevi,

The link that you send only shows how to change the image size when saving the image. As you can see from my code, I never save the image. The stream is set to bytes and these bytes go into the API. So somehow I need to change the size before setting the stream to bytes.

Thus note: the image never gets saved on the mobile device and I want to keep it that way.

I hope you understand my problem.

Kind regards,
Ganesh 


GG Ganesh Gebhard December 10, 2020 10:09 PM UTC

Update.

There have been some changes which raises some new questions.

The image gets saved properly on the device using ImageSaving. Now I need the help with the following:
After the image is saved, I want to load this image using the filepath and name (where ImageSaving saved the image) and delete the image.

Any help on how to do that?

Ganesh


RS Ramya Soundar Rajan Syncfusion Team December 11, 2020 03:16 PM UTC

Hi Ganesh Gebhard,  
  
Please find the consolidated update for your mentioned queries:  
  
As per your previous update, you are getting the saved stream from ImageSaving event, we would like to let you know that by default SfImageEditor compress the image from its original size by saving the image (since by default, it saved in .jpg format).  So, we have default inbuilt image compress option (through saving) alone.   
  
And as per your updated image saving event code, that will automatically save to the default image saved location. In order to avoid that, please set the Cancel property as True in ImageSaving event by referring to the below  
  
  
Your recent update shows like you are saving the image in the device, in order to change the location of the default image saved location, please refer to the below KB  
  
  
By referring to the above KB, you can provide your own desired file path and filename (image name) to save the image. From that saved image from location, you can do your own compress option which you did before.   
  
For deleting the file, by using default FileSystem’s Delete method  
  
  
Regards, 
Ramya S 



GG Ganesh Gebhard December 11, 2020 06:52 PM UTC

Hey! This works! Thanks a lot!


HM Hemalatha Marikumar Syncfusion Team December 14, 2020 04:22 AM UTC

Hi Ganesh Gebhard, 
 
Thanks for your feedback.  
 
Please let us know if you need any further assistance and don’t hesitate to contact us. 
 
Regards,
Hemalatha M.  



IG Ishani Guard March 12, 2021 07:59 PM UTC

Hi @Ganesh,

I am facing the same problem. After editing and saving, the size of original image drops and the new size is very small. Can you tell me how you managed to solve this? The image size of my original image was 5993kb which dropped to 126kb after editing and saving.

Thank you,
Ishani 


SS Sridevi Sivakumar Syncfusion Team March 15, 2021 12:05 PM UTC

Hi  Ishani Guard,

This update is mainly to get the confirmation of your reported issue to proceed with this without any misleading.

Have you saved the image in JPEG format?

If you are saving the image in JPEG format, the image quality will be lost from its original image quality and it is not our ImageEditor control side issue. (it’s framework side image process issue). To overcome this problem, you can save the image in PNG format.

Let us know if you need any further assistance.

Regards,
Sridevi S. 


Loader.
Up arrow icon