locked
Image not coming out the size I want RRS feed

  • Question

  • User-1355356054 posted

    I am rendering an image on a web page via an httphandler.

    The ContentType comes out as png and the BinaryWrite statement gets the image from the database.

    In our database, we have an imageid in one table which is associated with an image id as a foreign key in another table. The pertinent fields are ImageContent, Filename, Type, and Size.

    So, for instnace, two images coming out of the database have these values (I'm excluding the ImageContent, because it's obvioulsy too big):

     ImageId Scat Filename Type Size

    12   | ac1 | ac1.png | image/png | 16345

    259 | AV  | AV.png  | image/png | 21182

    The code for the handler is below. The question is: Is there any way to set the size of the image in the code behind inside the ProcessRequest method? I need all the image sizes to be 110x110.

    using Abb.Bll;
    
    using System;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    
    namespace YourLens.HttpHandlers
    {
      [WebService(Namespace = "http://abbconcise.com/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      public class GetSalesCategoryImage : IHttpHandler
      {
    
        public void ProcessRequest(HttpContext context)
        {
          string salesCategoryToFind = context.Request.QueryString["SalesCategory"];
    
          if (String.IsNullOrEmpty(salesCategoryToFind))
          {
            return;
          }
    
          SalesCategoryImage salesCategoryImage = SalesCategoryImageFactory.FindBySalesCategory(salesCategoryToFind);
          
          context.Response.ContentType = salesCategoryImage.Type;
          context.Response.BinaryWrite(salesCategoryImage.Image);
        }
    
        public bool IsReusable
        {
          get
          {
            return false;
          }
        }
      }
    }
    

     

    Thursday, July 26, 2012 4:58 PM

Answers

  • User-1828494216 posted

    Hi wsyeager36

    it is possible to resize the image. I would recomend to resize it before you store it unless you need the original format and even then you can create a thumbnail.

    There are a lot of example on the net about resizing images in .net. I know I have answered quite a few of those questions myself on this forum and I hate to sound like a parrot. I suggest you to use search engine ;)

    A quick search pops out: Resizing an Image without losing any quality

    If you have any aditional questions, please feel free to reply.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 26, 2012 5:21 PM