For a network experiment I am conducting, I require image files of arbitrary size.
I am lost on how to create such files. I require 5MB, 10MB and 20MB files in JPEG, PNG and PDF format.
In my first attempt at generating these files it became clear that due to the compression schemes of these formats, it's not possible (or at least I don't know how) to generate files of arbitrary size by just specifying resolution of blank files.
Is there a quick (programmatic?) method by which I could generate these files?
Edit: I am investigating creating arbitrarily sized dummy files, but if there is a way to create actual JPEG, PNGs or PDFs that have the correct internal format, that would be ideal.
The resolution doesn't change the number of pixels, just the display size of a pixel -- increasing resolution makes the display larger, but doesn't make the file larger.
If you make a JPEG that repeats the same information over and over again it will get bigger -- the compression is on a 8x8 cell basis -- if you have more cells, you'll have more data. To make them bigger, encode with quality set to 100. Another thing, JPEG strips out luminance on a cell basis, so variation in hue compresses worse than variation in luminance.
I used my company's product, DotImage, to create a 10mb jpg with this code. You could download an eval and try it out, or do the same with your image SDK.
using System;
using System.Drawing;
using Atalasoft.Imaging;
using Atalasoft.Imaging.Codec;
using Atalasoft.Imaging.Drawing;
namespace MakeLargeImage
{
class Program
{
static void Main(string[] args)
{
AtalaImage img = new AtalaImage(1000, 8000, PixelFormat.Pixel24bppBgr);
Canvas c = new Canvas(img);
for (int block = 0; block < img.Height; block += 1000)
{
for (int line = 0; line < 1000; line += 4)
{
int y = block + line;
c.DrawLine(new Point(0, y), new Point(img.Width, block), new AtalaPen(Color.Yellow));
c.DrawLine(new Point(0, y + 1), new Point(img.Width, y + 1), new AtalaPen(Color.Red));
c.DrawLine(new Point(0, y + 2), new Point(img.Width, y + 2), new AtalaPen(Color.Green));
c.DrawLine(new Point(0, block), new Point(img.Width, y + 3), new AtalaPen(Color.Blue));
}
}
JpegEncoder jpeg = new JpegEncoder(100);
img.Save("10mb.jpg", jpeg, null);
}
}
}
If you make the image pixel size larger, the JPEG file will get larger. You could also add in meta-data, but it's hard to get a big file with just meta-data as there are some size limitations.
PDF is the easiest -- just make a big page with uncompressed image and keep adding pages -- it will get big fast -- there's no compression unless you turn it on. You can do this easily in DotImage with the PdfEncoder
-- just give it a list of jpgs in a FileSystemImageSource
-- code not shown as to not bore everyone, but I'd be happy to provide it to anyone that wants it -- just call Atalasoft and ask for me (or open a support case and reference this question.