반응형
public static RenderTargetBitmap MergeImage(BitmapSource img1, BitmapSource img2)
{
var group = new DrawingGroup();
group.Children.Add(new ImageDrawing(img1, new Rect(0, 0, img1.PixelWidth, img1.PixelHeight)));
group.Children.Add(new ImageDrawing(img2, new Rect(0, 0, img2.PixelWidth, img2.PixelHeight)));
var drawingVisual = new DrawingVisual();
using (var drawingContext = drawingVisual.RenderOpen())
{
drawingContext.DrawDrawing(new DrawingImage(group).Drawing);
}
var bitmap = new RenderTargetBitmap(img1.PixelWidth, img1.PixelHeight, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(drawingVisual);
return bitmap;
}
public static RenderTargetBitmap MergeImage(List<BitmapSource> imgList)
{
var group = new DrawingGroup();
for (int i = 0; i < imgList.Count; i++)
{
group.Children.Add(new ImageDrawing(imgList[i], new Rect(0, imgList[i].PixelHeight * i, imgList[i].PixelWidth, imgList[i].PixelHeight)));
}
var drawingVisual = new DrawingVisual();
using (var drawingContext = drawingVisual.RenderOpen())
{
drawingContext.DrawDrawing(new DrawingImage(group).Drawing);
}
var bitmap = new RenderTargetBitmap(imgList[0].PixelWidth, imgList[0].PixelHeight * imgList.Count, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(drawingVisual);
return bitmap;
}
반응형
'[====== Development ======] > C#' 카테고리의 다른 글
C# Enum 타입을 int로 변환하는 Extention (0) | 2023.05.16 |
---|---|
C#으로 윈도우의 해상도와 배율 설정을 변경하는 방법 (0) | 2023.05.11 |
C# List에서 중복 제거한 리스트 만들기 (0) | 2023.04.06 |
WPF 컨트롤 위치값 구하기 (0) | 2023.03.28 |
C# JSON Array 읽는 방법 (0) | 2023.03.28 |