文件大小调整并将其保存到目标文件夹 [英] file resizing and saving it to a target folder

查看:106
本文介绍了文件大小调整并将其保存到目标文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须调整现有图像的大小并选择适当的宽度和高度。

现在这是代码我有这样的代码



图像已调整大小= ResizeImageForFull(原始,新大小(768,1024));



//将图像保存到内存流

MemoryStream memStream = new MemoryStream();

resized.Save(memStream,System.Drawing.Imaging.ImageFormat.Jpeg)





获取修改后的图像后将其保存到内存流中。任何人都可以帮我把它放到目标文件夹中保存为jpeg图像。





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.


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;
        }

推荐答案

Hello Lima3,



你'使用此方法保存图像:



Hello Lima3,

You're using this method to save the image:

public void Save(
    Stream stream,
    ImageFormat format
)





使用FileStream代替使用MemoryStream。



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



JAFC



Instead of using a MemoryStream, use a FileStream.

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

JAFC


这篇关于文件大小调整并将其保存到目标文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆