Solved

All type of  Image resize with 0%  quality loss

Posted on 2009-04-10
4
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Chad Smith earned 500 total points
ID: 24115365


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
ID: 24121225
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
ID: 24122055
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
ID: 24128128
how to write code for tostream as we had not created any file for that yet ?

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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