我从DataStream加载一个位图。我尝试从方法返回加载的位图,然后将其用作克隆新位图的源。不幸的是,Clone()调用导致OutOfMemoryException。通过测试,我意识到Clone()会成功,直到底层数据流被处理掉。
如何创建独立于加载流的位图?
DxScreenCapture cap = new DxScreenCapture();
var surface = cap.CaptureScreen();
Bitmap png;
Rectangle rect;
PixelFormat fmt;
using (DataStream stream = Surface.ToStream(surface, ImageFileFormat.Bmp))
{
png = new Bitmap(stream);
fmt = png.PixelFormat;
rect = new Rectangle(911, 170, 32, 14);
// Works
Bitmap rgn1 = png.Clone(rect, fmt);
}
// Throws OutOfMemoryException
Bitmap rgn2 = png.Clone(rect, fmt);
答案 0 :(得分:0)
根据Hans的评论,我只是从原来的位图创建了一个新的位图。
std::array<double, ARRAY_SIZE> A1 = {0};
// Here, I have some code that fills array A1 with random numbers using the rand() function
std::sort(A1.begin(), A1.end());
// some code that prints a selection of the A1 array.