이미지를 자르고 저장하는 과정이
입니다. 프로세스가 이미지를로드하고 자르고 원본 이미지를 삭제하여 (이를 대체 할 수 있음) 저장하고 저장하는 응용 프로그램이 있습니다.IOException이 처리되지 않았습니다.
private void DetectSize(object sender, EventArgs e)
{
int x = 1;
Bitmap TempImage = new Bitmap(@cwd + "\\t" + (x + 1) + ".jpg", true);
pictureBox.Image = (Image)TempImage.Clone();
TempImage.Dispose();
Bitmap imgPart = new Bitmap(pictureBox.Image);
int imgHeight = imgPart.Height;
int imgWidth = imgPart.Width;
HalfWidth = imgWidth/2;
MaxWidth = imgWidth;
try
{
Bitmap imgPart1 = new Bitmap(pictureBox.Image);
Color c;
for (int i = 0; i < imgPart1.Width; i++)
{
for (int j = 0; j < imgPart1.Height; j++)
{
c = imgPart1.GetPixel(i, j);
string cn = c.Name;
for (int z = 0; z <= 9; z++)
{
if (z < 10)
{
if (cn == "ff00000" + z)
{
if (i < HalfWidth)
{
MinWidth = i;
}
else
{
if (i < MaxWidth)
{
MaxWidth = i;
}
}
}
}
else
{
if (cn == "ff0000" + z)
{
if (i < HalfWidth)
{
MinWidth = i;
}
else
{
if (i < MaxWidth)
{
MaxWidth = i;
}
}
}
}
}
}
}
MinWidth += 1;
MaxWidth -= 1;
MaxWidth = imgWidth - MaxWidth;
imgPart1.Dispose();
imgPart.Dispose();
lblLeftMargin.Text = Convert.ToString(MinWidth);
lblRightMargin.Text = Convert.ToString(MaxWidth);
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
}
이 이미지를 잘라하는 데 사용됩니다 여백을 찾기위한 것입니다 :
이 내 코드입니다. 사용자 : \
private void CropSave(object sender, EventArgs e)
{
int x = 1;
Bitmap croppedBitmap = new Bitmap(pictureBox.Image);
croppedBitmap = croppedBitmap.Clone(
new Rectangle(
MinWidth, 0,
(int)croppedBitmap.Width - MinWidth - MaxWidth,
1323),
System.Drawing.Imaging.PixelFormat.DontCare);
if (System.IO.File.Exists(@cwd + "\\t" + (x + 1) + ".jpg"))
System.IO.File.Delete(@cwd + "\\t" + (x + 1) + ".jpg");
croppedBitmap.Save(@cwd + "\\t" + (x + 1) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
croppedBitmap.Dispose();
MessageBox.Show("File " + (x + 1) + "Done Cropping");
}
이 이미지
오류의 자르기 및 저장을위한 라인에 표시 System.IO.File.Delete(@cwd + "\\t" + (x + 1) + ".jpg"
는 프로세스가 파일 'C에 액세스 할 수 없습니다
말한다. ... \ t2.jpg '이 (가) 다른 프로세스에서 사용 중이기 때문입니다.
내가 며칠 동안 잘못 본 곳을 찾고 있습니다.
도와주세요.
가능한 중복 (http://stackoverflow.com/questions/3661799/file-delete-failureing-when-image-fromfile-before-it-made-making-copy) – BrokenGlass
코드의 관련 비트 만 게시하십시오. – svick
@svick - 문제는 거기에 있었고 나는 그것을 지적 할 수 없다고 생각합니다. 그래서 모든 코드를 게시하여 문제가되는 코드를 알려줄 수 있습니다 :) –