0

I want to display very large Image (36000 x 36000) So i tried use mat to load a very large image after make submat I used Mat made of SubMat as the Source of Image to be printed, but the image was not printed.

public BitmapImage[] loadBitmap(string fullpath)
{
     BitmapImage[] bitmap=new BitmapImage[4];
     using (var mat = Cv2.ImRead(fullpath, ImreadModes.Color))
                {
                    for (int i = 0; i < bitmap.Count(); i++)
                    {
                        //System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                        Mat submat= mat.SubMat(new OpenCvSharp.Rect(mat.Width / 2 * (i / 2), mat.Height / 2 * (i % 2), mat.Width / 2, mat.Height / 2));
                        Bitmap bit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(submat);
                        originImageWidth = mat.Width;
                        originImageHeight = mat.Height;

                        using (MemoryStream outstream = new MemoryStream())
                        {

                            BitmapImage _bitmap = new BitmapImage();

                            bit.Save(outstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            bit.Dispose();
                            outstream.Position = 0;
                            _bitmap.BeginInit();
                            _bitmap.StreamSource = outstream;
                            _bitmap.CacheOption = BitmapCacheOption.OnLoad;
                            _bitmap.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                            _bitmap.EndInit();
                            bitmap[i] = _bitmap;
                        }
                    }
                }

}

public System.Windows.Controls.Image[] image;
public void print()
{
    BitmapImage[] bitmaparray = loadBitmap(fullpath);
    image = new System.Windows.Controls.Image[4];
    for(int i=0;i<bitmaparray.Count();i++)
    {
         image[i].source = bitmaparray[i]; // << here image[i].pixelHeight,pixelWidth ==0 and image.Uri is null
         Canvas.SetLeft(image[i],bitmaparray[i].Width*(i%2));
         Canvas.SetTop(image[i],bitmaparray[i].Height*(i/2));
         canvas.Children.Add(image[i]); // not printed this canvas 
    }
    
}
Soo312
  • 1
  • Is that Canvas part of any visual tree? Have you checked the width and height of `bit` or tested the code with smaller SubMats or without `BitmapCreateOptions.PreservePixelFormat`? Besides that, the Left/Top positioning in the Canvas would only work because all bitmaps have the same size. Better use a UniformGrid. And `Uri` is of course null. You have never set it. – Clemens Dec 15 '20 at 07:42
  • You probably also want to use something like [this](https://stackoverflow.com/a/60749478/1136211) to convert Mat to ImageSource instead of encoding and decoding JPEGs. – Clemens Dec 15 '20 at 08:56

0 Answers0