Image resizing in .Net

Results 1 to 2 of 2

Thread: Image resizing in .Net

  1. #1
    Join Date
    Dec 1969

    Default Image resizing in .Net

    Here is the code I&#039;m using for resizing images in .Net, but after resizing some of my images have really bad quality.<BR><BR>What am I doing wrong here?<BR><BR><BR>//fil & fil2 = string with filenames<BR><BR>Bitmap orgImg;<BR>System.Drawing.Image newImg;<BR>orgImg = new Bitmap(fil);<BR>h = (500 * orgImg.Height) / orgImg.Width;<BR>newImg = orgImg.GetThumbnailImage(500,h,null,IntPtr.Zero);< BR>newImg.Save(fil2,ImageFormat.Jpeg);

  2. #2
    Join Date
    Dec 1969

    Default RE: Image resizing in .Net

    If you consult the documentation for the Save method, you will see that one of the overloads takes an array of EncoderParameters. You can use one of the EncoderParameters to set the quality. Here is the method I use to send a JPEG to the OutputStream:<BR>-----------------------------------------------------------------<BR> private void renderOutput() <BR> { <BR> int intJpgCodec; <BR><BR> //Get codecs <BR> ImageCodecInfo[] icf = ImageCodecInfo.GetImageEncoders(); <BR><BR> for(intJpgCodec = 0; intJpgCodec &#060; icf.GetUpperBound(0); intJpgCodec ++) <BR> { <BR> if(icf[intJpgCodec].FormatDescription == "JPEG") <BR> break; <BR> } <BR><BR> //Set quality <BR> EncoderParameters encps = new EncoderParameters( 2 ); <BR> EncoderParameter encp = new EncoderParameter( System.Drawing.Imaging.Encoder.Quality, <BR> (long) 100); <BR> encps.Param[0] = encp; <BR> Encoder myEncoder = Encoder.ColorDepth; <BR> encp = new EncoderParameter(myEncoder, 24L); <BR> encps.Param[1] = encp; <BR> m_objBmp.Save( Response.OutputStream, icf[intJpgCodec], encps ); <BR> }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts