Create image files of arbitrary file size

For the network experiment that I conducted, I need image files of arbitrary size.

I get lost in how to create such files. I need 5 MB, 10 MB, and 20 MB files in JPEG, PNG, and PDF formats.

In my first attempt to create these files, it became clear that due to the compression schemes of these formats, it is impossible (or at least I don’t know how) to generate files of arbitrary size simply by specifying the resolution of the empty files.

Is there a quick (programmatic?) Method with which I could generate these files?

Edit: I am studying the creation of arbitrary files of arbitrary size, but if there is a way to create real JPEG, PNG or PDF files that have the correct internal format, that would be ideal.

+3
source share
4 answers

Resolution does not change the number of pixels, just the size of the display increases the resolution of the pixel makes the display larger, but does not make the file larger.

If you make a JPEG that repeats the same information over and over, it gets bigger - compression based on 8x8 cells - if you have more cells, you will have more data. To make them bigger, encode with quality set to 100. Another thing is that JPEG emphasizes cell-based brightness, so shading changes less well than shading.

DotImage, 10- jpg . eval , 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);
        }
    }
}

, JPEG . , , .

PDF - - ​​ - , . DotImage PdfEncoder - jpgs FileSystemImageSource - , , , , - Atalasoft ( .

+1

. , .

, ?

(1)? jpg png .

(1) , , ( )

Edit:
, , jpg, , -, png.

#, . :

private void make_bitmap(int width, int height)
{
    Random random = new Random();
    Bitmap B = new Bitmap(width, height);
    int redvalue = 0;
    int greenvalue = 0;
    int bluevalue = 0;

    bool pick_random_color = true;
    for (int x = 0; x < width; x++)
    {
        for (int y = 0; y < width; y++)
        {
            Color col;
            if (pick_random_color)
            {
               col = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
            }
            else  // iterate over all colours repeatedly
            {   
                if (redvalue == 255) { redvalue = 0; greenvalue++; } else { redvalue++; }
                if (greenvalue == 256) { greenvalue = 0; bluevalue++; }
                if (bluevalue == 256) { redvalue = 0; greenvalue = 0; bluevalue = 0; }
                col = Color.FromArgb(redvalue, greenvalue, bluevalue);
            }
            B.SetPixel(x, y, col);
        }
    }
    B.Save("image.bmp");
    B.Save("image.jpg", ImageFormat.Jpeg);
    B.Save("image.png", ImageFormat.Png);
    B.Dispose();
}
+3

JPEG , JPEG? , . :

- #

+2

I would start with a “huge” file in all of these formats (by maximum file size), and then iteratively resize them using imagemagick convert until you find the specifics of your desired file.

You may need a trial version and an error (it can be easily written by a script), but you need to do it for a one-time experiment.

+1
source

Source: https://habr.com/ru/post/1725493/


All Articles