0

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 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!!

teocomi
  • 391
  • 1
  • 4
  • 5

2 Answers2

0

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;
    }
tkefauver
  • 491
  • 5
  • 19
-1

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

Community
  • 1
  • 1
J J
  • 1,550
  • 4
  • 17
  • 27
  • I see, but it's not using WPF... I've already manged to do that by creating a var bitmap = new Bitmap(width, height) but when it's too big (>25.000px) it throws the error "Parameter is not valid." – teocomi Jun 13 '11 at 08:53