QImage img(data_image, Nc, Nl, Nc, QImage::Format_Indexed8); // Создание таблицы цветов. QVector<QRgb> color_table; for(int i = 0; i < 256; ++i) { color_table.append(qRgb(i,i,i)); } img.setColorTable(color_table); QImage optimal_img = img.convertToFormat(QImage::Format_Mono); delete data_image; p.drawText(font_X,font_Y,setable_text); QGraphicsScene* scene = new QGraphicsScene(this); scene->setSceneRect(0,0,28400,28400); QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap::fromImage(optimal_img)); QGraphicsPixmapItem *item1 = new QGraphicsPixmapItem(QPixmap::fromImage(optimal_img)); QGraphicsPixmapItem *item2 = new QGraphicsPixmapItem(QPixmap::fromImage(optimal_img)); QGraphicsPixmapItem *item3 = new QGraphicsPixmapItem(QPixmap::fromImage(optimal_img)); QGraphicsPixmapItem *item4 = new QGraphicsPixmapItem(QPixmap::fromImage(optimal_img)); // на этот и следующий не хватает памяти QGraphicsPixmapItem *item5 = new QGraphicsPixmapItem(QPixmap::fromImage(optimal_img)); QGraphicsPixmapItem *item6 = new QGraphicsPixmapItem(QPixmap::fromImage(optimal_img)); scene->addItem(item); scene->addItem(item1); scene->addItem(item2); scene->addItem(item3); scene->addItem(item4); scene->addItem(item5); //scene->addItem(item6); item1->setPos(7100, 0); item2->setPos(0, 7100); item3->setPos(7100, 7100); item4->setPos(14200, 7100); item5->setPos(14200, 14200); item6->setPos(14200, 28400); ui->graphicsView->setScene(scene); 

I create a scene and place on it images with the size 7100х7100 format QImage::Format_Mono . When you try to create more than 5 objects of type QGraphicsPixmapItem images, a warning is issued that the RAM has QImage: out of memory, returning null image : QImage: out of memory, returning null image . It is really over, but I don’t really understand why QGraphicsPixmapItem objects take up so much space, because:

 QImage::Format_Mono The image is stored using 1-bit per pixel. 

Or am I misunderstanding something? And how, then, should I place at least 20-24 images on the stage? Sample image:

Sample image

  • Can you bring a piece of the image in question? Just take a very wild permission for a binary image. Maybe this is your texture, and you just need to take a small piece, and already stamp it with a brush. - alexis031182
  • @ alexis031182 Added an image, if you look closely, there are white pixels there. This is an image imitating a frame of a starry sky, formed from a photomatrix. - bronstein87
  • Well, then you do not need to create a bitmap. You get that useful information at least on an essentially huge background area. You need to work with a vector image. Keep in memory only the coordinates of points (stars). - alexis031182
  • Banal math says you need almost a memory gig. (one pixel - 4 bytes, one picture - 7100 * 7100 * 4 = about 192 MB). If the axis is 32bit, then it is quite possible that the memory is over. Do you really need such big pictures? Your monitor is hardly wider than 1920 pixels. - KoVadim
  • one
    @ bronstein87 I didn’t quite understand, the combat image will be a solid black background with white dots, or will the background be a non-uniform color (real sky) with gradients and modulations, and stars of different sizes? In the second case, the vector variant will not work. - Bearded Beaver

2 answers 2

At the request of workers, a small tutorial on using postscript for drawing vector graphics. The ps file is simply a text file with a description of the page markup. The file consists of consecutive commands, command parameters are written in front of the command and pushed onto the stack when the device parses the file. Examples of commands:

xy moveto moves the cursor to the specified point

xy lineto draws a line from the point where the cursor is to the specified

xy rmoveto / rlineto is the same, only the offset is indicated relative to the current position

after the end of the contour description, you need to call the stroke command that directly performs the drawing

xywh rectstroke draws a rectangle from xy point of width w and height h

The coordinate system operates with points, 0.0 in the lower left corner, default one point is 1/72 of an inch.

Code saving a primitive ps file:

 QFile file(QApplication::applicationDirPath()+"/out.ps"); QTextStream stream(&file); file.open(QIODevice::WriteOnly); stream << "%!PS-Adobe-2.0" << "\n"; //заголовочная строка, по ней корел определит, что это за файл. //Без нее файл является корректным с точки зрения синтаксиса, но в корел не импортируется :) stream << "20 20 500 500 rectstroke\n"; //рисуем прямоугольник stream << "newpath" << "\r\n"; //начинаем новую полилинию stream << "30 30 moveto " << "\r\n"; stream << "30 60 lineto " << "\r\n"; stream << "60 60 lineto " << "\r\n"; stream << "60 90 lineto " << "\r\n"; //описываем полилинию stream << "stroke" << "\r\n"; //непосредственно рисуем file.close(); 

When importing a file into CorelDraw, we see the following: When you import a file into CorelDraw, we see the following

I cited the basic principles and commands, the possibilities of the language (in fact, postscript is a page markup language) is much wider, there are many reference books on the Internet, it will not be difficult to figure out further.

    The QPixmap QPixmap::fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor) ( http://doc.qt.io/qt-5/qt.html#ImageConversionFlag-enum ) allows you to set the Qt::NoFormatConversion parameter Qt::NoFormatConversion , which prohibits the conversion of the original QImage format to RGB32 format with the alpha channel turned on. This method is suitable if you need to place as many images on the stage as possible to the detriment of the fact that scrolling and scaling them on QGraphicView becomes super slow and slow. (for me, this preview on QGraphicView is an additional feature and therefore this minus is not so critical).

    • You may be rushed. @BeardedBeaver did not seem to refuse to write an example for the vector. With a vector - the right decision in your situation. - alexis031182
    • @ alexis031182, if he writes, it will be great, and at least some way out :) - bronstein87