Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to re size an existing image and with proper width and height.
for now this is the code I have the code like this

Image resized = ResizeImageForFull(original, new Size(768, 1024));

//save the image to memory stream
MemoryStream memStream = new MemoryStream();
resized.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg)


after getting the modified image it is saved to the memory stream. can any one help me to put that into a target folder to save it as a jpeg image.


C#
public static Image ResizeImageForFull(Image image, Size size, bool preserveAspectRatio = true)
        {
            int newWidth=0;
            int newHeight=0;

            if (preserveAspectRatio)
            {
                newWidth = size.Width;
                newHeight = size.Height;
            }

            Image newImage = new Bitmap(newWidth, newHeight);
            using (Graphics graphicsHandle = Graphics.FromImage(newImage))
            {
                graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight);
            }

            return newImage;
        }
Posted

1 solution

Hello Lima3,

You're using this method to save the image:

SQL
public void Save(
    Stream stream,
    ImageFormat format
)


Instead of using a MemoryStream, use a FileStream.

http://msdn.microsoft.com/en-us/library/system.io.filestream(v=vs.110).aspx[^]

JAFC
 
Share this answer
 
Comments
Lima3 14-Nov-13 11:28am    
Can you give a sample on this. thanks
José Amílcar Casimiro 14-Nov-13 11:29am    
You have an example in the given link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900