首页 > 解决方案 > 如何在 C# 中显示非常大的图像?

问题描述

我想显示非常大的图像(36000 x 36000)所以我尝试使用垫子在制作子垫后加载一个非常大的图像我使用由 SubMat 制成的垫子作为要打印的图像源,但图像没有打印出来。

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

标签: c#wpfopencv

解决方案


推荐阅读