I am working on a small project to generate a large image in C++, on the order of 340000px by 34000px (10:1 ratio). The program basically draws a bunch of lines on the canvas. I need to save this image but I am having trouble coming up with an adequate way to do this. I cannut use a bmp as the image is too large to work with.
This is the code I'm working with:
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(340000, 34000);
this.Text = "";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int x, y, i, j, xOld, yOld, height, width, rays;
height = 33600;
width = 336000;
rays = 200;
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
Pen p = new Pen(Color.Black);
for (i = 1; i <= rays; i++){
//Drawing occurs here
}
p.Dispose();
}
private void Form1_Resize(object sender, System.EventArgs e)
{
Invalidate();
}
}
Any help in saving this image would be appreciate.
Comments
I suggest working at the file format level because otherwise, the code would basically involve having the whole image in RAM at a time which there is not enough memory for.
Since one of the simplest and somewhat efficient formats is bitmap, I suggest using that. If you can stick to a palette of 2 colours, you can limit yourself to 1 bit per pixel which would put a 340 000 by 34 000 pixel image at roughly 1.2GB lol.
You could use SVG(Scalable Vector Graphics) format to store the image and it would actually be very manageable. The file size would basically just depend on the number of lines you draw then. With vector graphics, the dimensions are basically meaningless, though. That is what puts the scalable in scalable vector graphics.
Assuming you want to keep it in a raster format, lets stick to the bitmap format. Draw your lines to a small version of the image so your program can keep track of the line positions but not all the pixel data. Remember that there isnt enough RAM to store all the pixels at a time. The small version is so you can actually do something practical with the image like look at it lol. 3000 by 300 should be a managable size. After storing a few lines at that scale, just multiply all the coordinates by 34000 over 300 to get the new line positions. Use the new scale in the following algorithm for writing the huge image:
Write the bitmap header.
Loop through each row of pixels.
{
For each row, draw the lines at full scale but clipping the region down to the current row of pixels.
Turn the pixels in the row into monochrome formatted bits.
Write the encoded row to the file.
}
Close the file.
If you want to learn more about the bitmap format to do this, I have a program
You can get the c++ source code here:
http://www.programmersheaven.com/d/click.aspx?ID=F54666
Another version was implemented with Java:
http://www.programmersheaven.com/d/click.aspx?ID=F54668
: I am working on a small project to generate a large image in C++, on
: the order of 340000px by 34000px (10:1 ratio). The program
: basically draws a bunch of lines on the canvas. I need to save this
: image but I am having trouble coming up with an adequate way to do
: this. I cannut use a bmp as the image is too large to work with.
:
: This is the code I'm working with:
:
:
: public class Form1 : System.Windows.Forms.Form
: {
: public Form1()
: {
: InitializeComponent();
: }
: private void InitializeComponent()
: {
: this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
: this.ClientSize = new System.Drawing.Size(340000, 34000);
: this.Text = "";
: this.Resize += new System.EventHandler(this.Form1_Resize);
: this.Paint += new
: System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
:
: }
: static void Main()
: {
: Application.Run(new Form1());
: }
:
: private void Form1_Paint(object sender,
: System.Windows.Forms.PaintEventArgs e)
: {
: int x, y, i, j, xOld, yOld, height, width, rays;
: height = 33600;
: width = 336000;
: rays = 200;
:
: Graphics g = e.Graphics;
: g.FillRectangle(Brushes.White, this.ClientRectangle);
: Pen p = new Pen(Color.Black);
:
: for (i = 1; i <= rays; i++){
: //Drawing occurs here
: }
: p.Dispose();
: }
: private void Form1_Resize(object sender, System.EventArgs e)
: {
: Invalidate();
: }
: }
:
: Any help in saving this image would be appreciate.
: