Lost quality when drawing JPG onto another JPG

Last post 07-10-2009 7:57 AM by hoainam_vsdc. 0 replies.

Sort Posts:

  • Lost quality when drawing JPG onto another JPG

    07-10-2009, 7:57 AM
    • Member
      17 point Member
    • hoainam_vsdc
    • Member since 09-18-2007, 11:14 PM
    • Posts 33

    Hi all

    I have 2 jpeg file, a bigger one and a smaller one, both is created and export by Adode Photoshop with maximum quality (12)

    (the content of the 2 jpg is quite simple, just some colored text)

    But when try to overlay the smaller image onto the bigger image (by GDI+), the DrawImage did lost quality.

    (I aslo DrawString in colorful within the bigger JPG but the quality is nice). Below is my code


    		System.Drawing.Image result = Bitmap.FromFile(...............);
    		Graphics g = Graphics.FromImage(result);
    
    		g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    		g.PixelOffsetMode = PixelOffsetMode.HighQuality;
    		g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    		g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
    		g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
    
    		EncoderParameters encoderParams = new EncoderParameters(1);
    		encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100);
    
    		ImageCodecInfo[] imageCodecInfoArray = ImageCodecInfo.GetImageEncoders();
    		ImageCodecInfo imageCodecInfo = null;
    		for (int i = 0; i < imageCodecInfoArray.Length; i++)
    		{
    			if (imageCodecInfoArray[i].MimeType == "image/jpeg")
    				imageCodecInfo = imageCodecInfoArray[i];
    		}
    
    		System.Drawing.Image smallImage = Bitmap.FromFile(...);
    		g.DrawImage(smallImage, new Point(0, 0));
    
    Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType = "image/jpeg"; Response.AddHeader("Content-Disposition", "inline;filename=test.jpg"); result.Save(Response.OutputStream, imageCodecInfo, encoderParams); result.Dispose(); Response.Flush(); Response.End();

    Can Anyone help

    Thanks

Page 1 of 1 (1 items)