c# - 如何在 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
}
}
解决方案
推荐阅读
- angular - Ionic:如何在一个模块中有多个方法以及如何在模板中显示结果?
- swift - 使用 NSCoding 保存结构
- python - pyqt4鼠标释放事件未触发
- apache-spark - 在 Pyspark 数据框中将 2 列的数据合并为 1 列
- c - C中带有数组的指针
- c# - SQL Server 数据库特殊查询
- c# - 子目录中带有 Wordpress 的 Asp.Net MVC Core 2 网站
- r - JAGS 错误消息 - 节点与父节点不一致
- apache-spark - 使用 Kafka 和 Spark Streaming 为 Web 应用程序提供服务
- android - 自定义 Table-like ViewGroup