imageComponent.NET - image processing .NET assemblies
Image Processing in ASP.NET

PhotoController SDK is able to work with ASP.NET. What you need is to add the assembly to the website reference, and call the method within the object to perform any image processing operation you want. The following is an example that loads an image, apply an Emboss effect, then render to the page.

   1:  // decalres the page output content type
   2:  Response.ContentType = "image/jpeg";
   3:   
   4:  // initialize a new instance of PhotoController
   5:  IC.PhotoController.Controller objpc = new Controller();
   6:   
   7:  // load the image to the controller
   8:  System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("..") + "\\PhotoControllerWebDemo\\test.jpg”);
   9:  objpc.LoadImage(img);
  10:   
  11:  // create an EmbossFilter
  12:  EmbossFilter filter = new EmbossFilter();
  13:  filter.Level = 3;
  14:  filter.Direction = 120;
  15:   
  16:  // apply the filter algorithm
  17:  img = objpc.Filter(filter);
  18:   
  19:  // create a bitmap object with the resulted image
  20:  Bitmap b = new Bitmap(img);
  21:  System.IO.MemoryStream oStream=new System.IO.MemoryStream();
  22:  Response.ClearContent();
  23:  b.Save(oStream,System.Drawing.Imaging.ImageFormat.Jpeg);
  24:   
  25:  // output the bitmap to the page
  26:  Response.BinaryWrite(oStream.ToArray());
  27:   
  28:  // release all resources
  29:  objpc.Dispose();
  30:  img.Dispose();
  31:  b.Dispose();
  32:  Response.End();

The following VB.NET code does the same thing above:

   1:  // decalres the page output content type
   2:  Response.ContentType = "image/jpeg"
   3:   
   4:  // initialize a new instance of PhotoController
   5:  Dim objpc As IC.PhotoController.Controller
   6:  objpc = New IC.PhotoController.Controller
   7:   
   8:  // load the image to the controller
   9:  Dim img As System.Drawing.Image
  10:   
  11:  img = System.Drawing.Image.FromFile(Server.MapPath("..") + "\PhotoControllerWebDemoVB\test.jpg”)
  12:  objpc.LoadImage(img)
  13:   
  14:  // create an EmbossFilter
  15:  Dim filter As EmbossFilter = New EmbossFilter()
  16:  filter.Level = 3
  17:  filter.Direction = 120
  18:   
  19:  // apply the filter algorithm
  20:  img = objpc.Filter(filter)
  21:   
  22:  // create a bitmap object with the resulted image
  23:  Dim b As Bitmap
  24:  b = New Bitmap(img)
  25:   
  26:  Dim oStream As New System.IO.MemoryStream
  27:  Response.ClearContent()
  28:  b.Save(oStream, System.Drawing.Imaging.ImageFormat.Jpeg)
  29:   
  30:  // output the bitmap to the page
  31:  Response.BinaryWrite(oStream.ToArray())
  32:   
  33:  // release all resources
  34:  objpc.Dispose()
  35:  b.Dispose()
  36:  img.Dispose()
  37:  Response.End()

Suppose the above code-behind belongs to a file called DisplayImage.aspx, you need another page to display the image. For example, you can use the following line:

   1:  <img src="DisplayImage.aspx"> 

[Back to Top]
Comments

If you feel this page can be improved or has any mistake, please enter your valuable opinion here. Or if you cannot find the information you are after, feel free to suggest a subject too. I appreciate any voice.

Your Name:
  
Your Email Address:
  
Comments: