디렉토리를 사용하고 새로운 "resizedDirectory"(존재하지 않는 경우)를 만들고, 모든 .bmp를 크기 조정 한 다음 " resizedDirectory ". 이것은 내가 (일부 지역을 위해 인터넷을 사용)과 같은 기능을 작성한 것은 이번이 처음이다, 여기에 코드입니다 :ASP/C#, 새로운 비트 맵() "메모리 부족"
protected void directorySelected(object sender, EventArgs e) {
// Make sure the directory exists
if (Directory.Exists(inputDirectory.Text)) {
string[] filePaths = Directory.GetFiles(inputDirectory.Text);
// Determine if there are any files in inputDirectory
if (filePaths.Length == 0) messageLog.InnerHtml = "<strong>No files found in:</strong> "+inputDirectory.Text;
else {
// Determine if "resizedDirectory" exists, create it if it does not exist
string resizedDirectory = inputDirectory.Text+"\\"+"resizedDirectory";
if (!Directory.Exists(resizedDirectory)) {
Directory.CreateDirectory(resizedDirectory);
messageLog.InnerHtml = "<strong>Created:</strong> "+resizedDirectory+"<br/><br/>";
}
// For each file in inputDirectory...
for (var i = 0; i < filePaths.Length; i++) {
string[] extensionSplit = filePaths[i].Split('.');
// Make sure filePath[i] ends with the appropriate extension
if (extensionSplit.Length == 2 && extensionSplit[1].Equals("bmp")) {
Bitmap currImage = new Bitmap(filePaths[i]);
messageLog.InnerHtml += "<strong>"+i.ToString()+":</strong> "+filePaths[i]+"<br/><div class='indent'>";
// Calculate new dimensions
int newWidth = maxWidth;
int newHeight = maxHeight;
if (currImage.Width > currImage.Height) newHeight = (int)(((float)maxWidth)/((float)currImage.Width)*currImage.Height);
else newWidth = (int)(((float)maxHeight)/((float)currImage.Height)*currImage.Width);
messageLog.InnerHtml += "<strong>Old dimensions:</strong> ("+currImage.Width+","+currImage.Height+")<br/><strong>New dimensions:</strong> ("+newWidth+", "+newHeight+")<br/>";
// Settings before saving
Bitmap targetImage = new Bitmap(newWidth, newHeight);
using (Graphics g = Graphics.FromImage(targetImage)) {
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawImage(currImage, 0, 0, newWidth, newHeight);
}
ImageCodecInfo ici = this.GetEncoderInfo(ImageFormat.Bmp);
Encoder eq = Encoder.Quality;
EncoderParameters eps = new EncoderParameters(1);
EncoderParameter ep = new EncoderParameter(eq, 100L); // 100L is the higest quality (goes from 0 - 100)
eps.Param[0] = ep;
// Save image
string targetPath = resizedDirectory+"\\foo"+i.ToString()+".bmp";
targetImage.Save(targetPath, ici, eps);
messageLog.InnerHtml += "<strong>Saved:</strong> "+targetPath+"</div><br/>";
}
else messageLog.InnerHtml += "<strong>IGNORED "+i.ToString()+":</strong> "+filePaths[i]+"<br/>";
}
}
}
else if (inputDirectory.Text.Equals("")) messageLog.InnerHtml = "<strong>No directory specified</strong>";
else messageLog.InnerHtml = "<strong>Cannot find:</strong> "+inputDirectory.Text;
}
protected ImageCodecInfo GetEncoderInfo(ImageFormat format) {
return ImageCodecInfo.GetImageDecoders().SingleOrDefault(c => c.FormatID == format.Guid);
}
이 작은 .bmps로 괜찮 았는데. 문제는 변환해야 할 .bmp 파일의 디렉토리가 크기 때문에 예제 .bmp는 16073 x 13231 (또는 608MB)입니다. 작은 .bmp와 거대한 .bmp 중 하나를 사용하여 코드를 시도하고 "resizedDirectory"를 작성하여 작은 크기의 새 크기 조정 .bmp를 만든 다음 "메모리 부족"메시지와 함께 충돌합니다.
거대한 .bmps의 크기를 조정하려면 어떻게해야합니까?
편집 : 그것은 하나의 거대한 .BMP에 실패 (하지만 작은 것들에)
제발 다시 태그 질문 :이 ... 그것은 하나의 거대한 .BMP에 실패 –