Language - C#/C#(UI - WINFORM)
C# - Bitmap Image 합성
KimTory
2021. 11. 17. 20:19
▶ Language : C#
▶ IDE : Visual Studio 2017
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
// load image path
string filepath = string.Empty;
// save image path
string savepath = string.Empty;
// save image 고정 size
public readonly int imageWidth = 3840;
public readonly int imageHeight = 2748;
// forlderBrowserDialog 이용하여 image load path 저장
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
filepath = this.folderBrowserDialog1.SelectedPath;
// forlderBrowserDialog 이용하여 image save path 저장
if (this.folderBrowserDialog2.ShowDialog() == DialogResult.OK)
savepath = this.folderBrowserDialog2.SelectedPath;
// width, heigth size
using (Bitmap myBitmap = new Bitmap(imageWidth * 2, imageHeight, PixelFormat.Format32bppRgb))
{
// Graphics 이용하여 bitmap image 각 위치에 그리기 위함
Graphics mygraphics = Graphics.FromImage(myBitmap);
// image 2개 개별 저장
Bitmap drawingBitmap1 = new Bitmap(filepath + "\\tx_1" + ".bmp");
Bitmap drawingBitmap2 = new Bitmap(filepath + "\\tx_2" + ".bmp");
// x,y,width,height
mygraphics.DrawImage(drawingBitmap1, 0, 0, drawingBitmap1.Width, drawingBitmap1.Height);
mygraphics.DrawImage(drawingBitmap2, drawingBitmap1.Width, 0, drawingBitmap1.Width, drawingBitmap1.Height);
myBitmap.Save(savepath + "\\" + ".bmp", ImageFormat.Bmp);
drawingBitmap1.Dispose();
drawingBitmap2.Dispose();
mygraphics.Dispose();
}