Reputation: 33
I have a collection of Bitmaps that are stored in a List<byte[]>
object. I want to combine all those Bitmap
s into one image (kinda like a paneramic) without converting them back to bitmaps. I've tried using a MemoryStream
(see below) but it doesn't seem to work. I always run out of memory or the image comes out corrupted. I would appreciate any thoughts/advice on the matter.
List<byte[]> FrameList = new List<byte[]>();
using (MemoryStream ms = new MemoryStream())
{
for (int i = 0; i < FrameList.Count; i++)
{
//Does not work
ms.Write(FrameList[i], i * FrameList[i].Length, FrameList[i].Length);
//Does not work
ms.Write(FrameList[i], 0, FrameList[i].Length);
}
Bitmap img = (Bitmap)Bitmap.FromStream(ms);
img.Save("D:\\testing.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
Upvotes: 0
Views: 279
Reputation: 9502
The steps:
calculate the final image size as sum of size of the individual images
create a Bitmap
with the final size
get the Graphics
object
draw all images using the Graphics
object
save the final Bitmap
var final = new Bitmap(width, height); // calculated final size
using (var graphics = Graphics.FromImage(final))
{
graphics.DrawImage(...); // draw all partial images onto the final bitmap
}
Upvotes: 1