1

Is there anyone able to tell me how could i re-size an image read from a Sitecore ImageField?

After i read it from that specific image field, i form a Sitecore MediaItem from it and generate its 64 bit representation. The problem is that it comes into a greater size that I needed to.

Can anyone please help me?

Best regards, Marius.

Marius Popa
  • 564
  • 1
  • 5
  • 22

1 Answers1

2

I guess you are converting the image via MediaItem.GetMediaStream(), building a byte array of it and after that you are building a base64 string out of the image. The problem of resizing now becomes a .net problem rather than Sitecore`s. There are several ways to resize image in c#. You can refer to this post s on stack overflow on how to resize the image:

How I can resize the image in c#?

Resize image on the fly in .net and c#

If you decide to drop the code part for resizing and use the Sitecore MediaManager instead there are query string params which will help you resize the image itself. You can refer to this blog post for more information about the query string parameters.

Community
  • 1
  • 1
nsgocev
  • 4,390
  • 28
  • 37
  • Yes you are right about the conversion. So, for example, regarding the second link that you provided, how should i use it in my case? From what should i form my Bitmap image as it's described there? – Marius Popa Sep 16 '14 at 13:09
  • 1
    @MariusPopa you can use the stream you get from GetMediaStream() – nsgocev Sep 16 '14 at 13:11
  • Thank you very much for your help. I created a Image from the MediaItem.GetMediaStream() and did all the processing on that. – Marius Popa Sep 16 '14 at 13:35