我生成縮略圖,一切順利,但在創建子文件夾時出現問題。假設:縮略圖生成期間的文件夾創建問題c#
C:\用戶\ A \桌面\ B測試\冰島\ Haskolinn2 目標縮略圖文件夾將是這樣的: C:\用戶\ A \桌面\測試\冰島 * C:\用戶\ A \桌面\測試\ Haskolinn2 *
它必須看起來像 C:\用戶\ A \桌面\測試\冰島\ Haskolinn2
這裏是代碼:
public void CreateThumbnail(double wid, double hght, bool Isprint)
{
string saveAt = "C:\\Users\\a\\Desktop\\a test";
string b= "C:\\Users\\a\\Desktop\\b test\\iceland"
string [] bb = Directory.GetDirectories(b, "*.*", SearchOption.AllDirectories);
foreach (string path in bb)
{
var directory = new DirectoryInfo(path);
string outputPath = Path.Combine(saveAt, directory.Name);
foreach (FileInfo f in directory.GetFiles("*.*", SearchOption.AllDirectories))
{
if (f.DirectoryName != directory.FullName)
{
outputPath = Path.Combine(saveAt, directory.Name);
}
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
using (Image imagesize = Image.FromFile(f.FullName))
using (Bitmap bitmapNew = new Bitmap(imagesize))
{
double maxWidth = wid;
double maxHeight = hght;
int w = imagesize.Width;
int h = imagesize.Height;
// Longest and shortest dimension
int longestDimension = (w > h) ? w : h;
int shortestDimension = (w < h) ? w : h;
// propotionality
float factor = ((float)longestDimension)/shortestDimension;
// default width is greater than height
double newWidth = maxWidth;
double newHeight = maxWidth/factor;
// if height greater than width recalculate
if (w < h)
{
newWidth = maxHeight/factor;
newHeight = maxHeight;
}
string fileName = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(f.Name) + ".jpeg");
bitmapNew.GetThumbnailImage((int)newWidth, (int)newHeight,() => false, IntPtr.Zero)
.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
}
}
問題是什麼(也有任何錯誤消息可能有幫助)? – SWeko 2011-03-22 09:16:05
@SWeko不存在錯誤,但在物理文件系統上,目錄結構與原始文件系統不同。子文件夾不是作爲子文件夾創建的,而是作爲父文件夾創建的。假設文件夾A包含兩個子文件夾(B,C),所以在目的地它會像(A,B,C)這是錯誤的。 – safi 2011-03-22 09:18:26
'jak'中的文件夾結構是什麼?在上面的例子中你沒有使用過'b'。 – 2011-03-22 09:25:26