如何从文件夹创建目录和保存图像(服务器路径) [英] How to create directory and save image from folder (server path)
本文介绍了如何从文件夹创建目录和保存图像(服务器路径)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我必须在C或D中创建一个目录,如D:\ New文件夹,需要从Root目录下的文件夹下载图像(服务器路径)请提供解决方案....提前谢谢。
我的尝试:
hi I have to create one directory in C OR D like D:\New Folder and need to download image from folder which we have in Root directory(server path) please provide me the solution....thank in advance.
What I have tried:
const string Folder = @"D:\New Folder";
string strImage = "Images\\1.jpg";
Response.Clear();
Response.ContentType = "image/jpg";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + strImage);
//Response.TransmitFile(folderpath);
Response.WriteFile(strImage, true);
File.WriteAllText(Path.Combine(Folder), strImage);
Response.Flush();
Response.End();
推荐答案
public void ResizeImage(string origFileLocation, string newFileLocation, string newFileName, int newWidth, int maxHeight, bool resizeIfWider)
{
try
{
System.Drawing.Image FullSizeImage = System.Drawing.Image.FromFile(origFileLocation);
// Ensure the generated thumbnail is not being used by rotating it 360 degrees
FullSizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
FullSizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
if (resizeIfWider)
{
if (FullSizeImage.Width <= newWidth)
{
//newWidth = FullSizeImage.Width;
}
}
int newHeight = FullSizeImage.Height * newWidth / FullSizeImage.Width;
if (newHeight > maxHeight) // Height resize if necessary
{
//newWidth = FullSizeImage.Width * maxHeight / FullSizeImage.Height;
newHeight = maxHeight;
}
newHeight = maxHeight;
// Create the new image with the sizes we've calculated
System.Drawing.Image NewImage = FullSizeImage.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
FullSizeImage.Dispose();
NewImage.Save(Path.Combine(newFileLocation, newFileName));
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
origFileLocation : Original file location(Source Folder)
newFileLocation : New file location(Destination Folder)
newFileName : new file name to be saved to destination folder
你可以如果您不想要图像大小调整逻辑,则更改该功能
You may alter the function if you do not want image resize logic
这篇关于如何从文件夹创建目录和保存图像(服务器路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文