开发者

C# combine lots of images - WPF Imaging classes

Hello i'm combining lots of tiles into one big image. Folloging this guide: http://www.switchonthecode.com/tutorials/combining-images-with-csharp it works fine but just if the size of the final image isn't 开发者_C百科too big (otherwise I get "Parameter is not valid." error).. So googling I read I'd better use WPF Imaging classes, but I can't find a way to do it...

Could someone point me to a tutorial or tell me ho to do so?

Thanks!!


I know this is is an old question but just encountered this problem with WPF and none of the solutions I found directly answered the question but the below method merges a List of BitmapSource's so the output image is the max dimensions of the images in the list:

public static BitmapSource MergeImages(IList<BitmapSource> bmpSrcList) {
        int width = 0,height = 0,dpiX = 0,dpiY = 0;
        // Get max dimensions and dpi of the images
        foreach (var image in bmpSrcList) {
            width = Math.Max(image.PixelWidth,width);
            height = Math.Max(image.PixelHeight, height);
            dpiX = Math.Max((int)image.DpiX, dpiX);
            dpiY = Math.Max((int)image.DpiY, dpiY);
        }
        var renderTargetBitmap = new RenderTargetBitmap(width, height, dpiX, dpiY, PixelFormats.Pbgra32);
        var drawingVisual = new DrawingVisual();
        using (var drawingContext = drawingVisual.RenderOpen()) {
            foreach (var image in bmpSrcList) {
                drawingContext.DrawImage(image, new Rect(0, 0, width, height));
            }
        }
        renderTargetBitmap.Render(drawingVisual);

        return renderTargetBitmap;
    }


The first answer here should give you an idea... Basically creating a canvas that is the combined size and then positioning the 'tiles' appropriately.

Merging two images in C#/.NET

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜