Solved

All type of  Image resize with 0%  quality loss

Posted on 2009-04-10
4
247 Views
Last Modified: 2012-05-06
Hello Experts,

We are developing one website using ASp.net 2.0 and sqlserver 2005.

User can upload any size of image and their snaps from website just like picasa and other sites.

there is no size restriction they can upload any size image.

i just want to resize it  with same image ratio but image quality needs to be maintain. it shoul not get distorted.

is that possible using any component ? or

we can manage it through coading ?

Thanks.
Kinjal
0
Comment
Question by:dotsandcoms
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Chad Smith earned 500 total points
Comment Utility



public void ResizeImage(double scaleFactor, Stream fromStream,Stream toStream)

{

    var image = Image.FromStream(fromStream);

    var newWidth = (int)(image.Width * scaleFactor);

    var newHeight = (int)(image.Height * scaleFactor);

    var thumbnailBitmap = new Bitmap(newWidth, newHeight);

 

    var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);

    thumbnailGraph.CompositingQuality =CompositingQuality.HighQuality;

    thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;

    thumbnailGraph.InterpolationMode =InterpolationMode.HighQualityBicubic;

 

    var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);

    thumbnailGraph.DrawImage(image, imageRectangle);

 

    thumbnailBitmap.Save(toStream, image.RawFormat);

 

    thumbnailGraph.Dispose();

    thumbnailBitmap.Dispose();

    image.Dispose();

}

 

Open in new window

0
 

Author Comment

by:dotsandcoms
Comment Utility
Can i have input values for  fromstream and tostream ?

I mean code to assign input values for fromstream and tostream


0
 
LVL 10

Expert Comment

by:Chad Smith
Comment Utility
This code will put an Image into a MemoryStream
            MemoryStream ms = new MemoryStream();

            Image img = Image.FromFile("file.name");

            img.Save(ms, ImageFormat.Jpeg);

Open in new window

0
 

Author Comment

by:dotsandcoms
Comment Utility
how to write code for tostream as we had not created any file for that yet ?

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now