안녕하세요 여러개의 이미지 로컬파일을 가지고 하나의 이미지로 합쳐서
일종의 썸네일처럼 써보려고 하는데요,
합치는것 까지는 문제없이 되는데 이미지가 좀 잘려보이는 느낌이 있습니다.
모든 이미지의 사이즈는 동일한데도 그러네요
- 이미지 경로 리스트 로드
- 결과이미지를 그릴 bitmap 객체를 전체 이미지의 가로세로 길이를 계산해서 생성
- 이미지 경로리스트를 반복문 돌면서 이미지 로드, 그래픽스 객체를 이용해서 bitmap에 좌표를 설정해서 그림
아래 코드는 이미지를 병합하는 코드입니다.
string FolderName = diPath;
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(FolderName);
foreach (System.IO.FileInfo File in di.GetFiles())
{
string FileNameOnly = File.Name.Substring(0, File.Name.Length - 4);
string FullFileName = File.FullName;
imagePathList.Add(FullFileName);
}
Image newImg = Image.FromFile(imagePathList[0]);
int newWidth = newImg.Width * THUMNAIL_MAX_WIDTH_COUNT;
int newHeight = newImg.Height * THUMNAIL_MAX_HEIGHT_COUNT;
Bitmap bitmap = new Bitmap(newWidth, newHeight);
using (Graphics g = Graphics.FromImage(bitmap))
{
int imgPointX = 0;
int imgPointY = 0;
int index = 0;
foreach (string imgPath in imagePathList)
{
using(Image image = Image.FromFile(imgPath))
{
g.DrawImage(image, imgPointX, imgPointY);
if(index % THUMNAIL_MAX_WIDTH_COUNT == THUMNAIL_MAX_WIDTH_COUNT - 1)
{
imgPointX = 0;
imgPointY += image.Height;
}
else
{
imgPointX += image.Width;
}
index++;
}
}
}
string result = thumnailPath + "\\result.jpg";
bitmap.Save(result, ImageFormat.Jpeg);
아래는 결과물 예시입니다. 모든 이미지 크기는 같은데 묘하게 이미지가 조금씩 왜 잘리는지 잘 모르겠네요…