O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Explicitly encoding your content

You can also choose to explicitly encode your content. The image encoder, for instance, encodes images to PNG files. If you want to encode the image to another file format, you can explicitly do so, as follows:

private void ReturnMomentaryAsJpg(HttpRequest Request, 
   HttpResponse Response) 
{ 
   SKImage Gauge = this.GenerateGauge(Request.Header); 
   SKData Data = Gauge.Encode(SKEncodedImageFormat.Jpeg, 90); 
   byte[] Binary = Data.ToArray(); 
 
   Response.ContentType = "image/jpeg"; 
   Response.Write(Binary); 
} 

Here you must explicitly set the content type of the response and then write the binary encoded data to the response stream.

You can now run the application and test it by typing in the URL of your new resource.

To test ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required