Sachin jadhav
Sachin jadhav

Reputation: 11

Printing Canvas to image silverlight

I have scuccesfully added canvas to bitmap using WritebleBitmap class and then trying to use the bitmap to save image on client system through SaveFileDilogue. I am using the method of FluxJpegCore image encoding where we use raster arrays to generate image pixel-wise. Below is the part of the code which does the job.

        byte[][,] raster = new byte[bands][,];

        for (int i = 0; i < bands; i++)
        {
            raster[i] = new byte[width, height];
        }

        for (int row = 0; row < height; row++)
        {
            for (int column = 0; column < width; column++)
            {
                int pixel = bitmap.Pixels[width * row + column];
                raster[0][column, row] = (byte)(pixel >> 16);
                raster[1][column, row] = (byte)(pixel >> 8);
                raster[2][column, row] = (byte)pixel;
            }
        }    

All goes fine with image saving, however when i zoom the image and then print it, the code fails at the line "raster[i] = new byte[width, height];". System out of memory error is raised. Can anyone help me to find the solution on this?

Upvotes: 1

Views: 552

Answers (2)

MyKuLLSKI
MyKuLLSKI

Reputation: 5325

Going with @AnthonyWJones I'm pretty sure width or height is something like double.NAN. Make sure you place a check to see is width and height is a real number. Also check that your array does not a lot for more than possible within Silverlight

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189457

I'm not sure there is a solution to be had. You have 3 arrays that each need a contiguous 163MB block of memory. The problem will be that the process does not have 3 such address blocks available that are that size.

Bear in mind also that the bitmap.Pixels will be an array 653MB big.

Your only real hope(s) would be to

  1. Use the app OOB, hopefully VM fragmentation would be limited and allow such very large arrays to be allocated.
  2. If FluxJpegCore can use Stream instead of a byte array and does so effeciently (still a lot of work for you to do there)
  3. Move up to Silverlight 5 and host your app in a 64 bit browser instance.

Upvotes: 2

Related Questions