Introduction

In this article, you will see the use of the WebImage helper in the Web API. For using the WebImage helper we use the "System.Web.Helper" namespace. The WebImage helper is used for displaying and managing the image on the Web Page,.

The following are the properties of the WebImage Helper:

The following are the methods of the WebImage Helper:

Let's see an example.

Step 1

Create a Web API application as in the following:

Step 2

Now select the "HomeController".

Add the following code:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Helpers;
  6. using System.Web.Mvc;
  7. namespace MvcApplication16.Controllers
  8. {
  9. public class HomeController : Controller
  10. {
  11. public ActionResult Index()
  12. {
  13. return View();
  14. }
  15. public void SelectPicture()
  16. {
  17. WebImage img = new WebImage("~/images/Image1.jpg");
  18. img.Resize(200,200);
  19. img.FileName= "Image1.jpg";
  20. img.Write();
  21. }
  22. public void SelectPicture1()
  23. {
  24. WebImage img = new WebImage("~/images/Image2.jpg");
  25. img.Resize(250, 250);
  26. img.FileName = "Image2.jpg";
  27. img.Write();
  28. }
  29. public void SelectPicture2()
  30. {
  31. WebImage img = new WebImage("~/images/Desert.jpg");
  32. img.Resize(200, 200);
  33. img.FileName = "Desert.jpg";
  34. img.RotateLeft();
  35. img.Write();
  36. }
  37. }
  38. }

Step 3

Now write some HTML code in the "index.cshtml" file. This file exists:

Add the following code:

  1. <html>
  2. <head>
  3. <title>Index</title>
  4. </head>
  5. <body>
  6. <div>
  7. <img src="@Url.Action("SelectPicture")" alt="" />
  8. <img src="@Url.Action("SelectPicture1")" alt="" />
  9. <img src="@Url.Action("SelectPicture2")" alt="" />
  10. </div>
  11. </body>
  12. </html>

Step 4

Execute the application as in the following:

Output