convert Qt qml file to bit map image - c++

I want to take a qml I created in the QTCreator and transform it to a bmp image.
what I want in the bmp image is just the items I created.
I read about grabWindow but this is not realy what I want because it takes a snapshot of the screen and not creating bmp image with only the items in the qml.
Thanks

From QML:
youritem.grabToImage(function(result) {
result.saveToFile("something.bmp");
});
Although a bmp image is a bad idea, those things are huge. png is the best candidate for QML stuff, which is usually more "vector-y".

Related

Display partially loaded image by QImage

I'm using QImage class from Qt to display the picture on screen. For some reason I need to display even not fully loaded images (e.g. when some data blocks are absent).
I would like to see something like this in result:
Standard image viewer for Windows can show me such broken images, but I can’t achieve same behavior with QImage. Image not displayed at all if broken. Is there a way to display a partially loaded image by QImage? Maybe I should use other Qt-related classes for that purpose?
QImage is probably too high level for this. If you do not want to go at the level of individual libraries for each format (e.g. libpng), you should consider using CImg. It is a small header only c++ library to read and process images, which use the low level libraries available to read images. From a loaded CImg you should be able to get the data into a QPixmap or QImage to display it.

How to set a background for my form in c++builder6?

I am new to C++Builder 6, but I have used C++. My question is, how do I set a background for my form? When I open the application I want the background to have a specific image. I tried with Graphics::TBitmap but it says that the image is not valid even if it is bmp.
Graphics::TBitmap *BmpTabla = new Graphics::TBitmap;
try {
BmpTabla->LoadFromFile("board.bmp");
}
__finally
{
delete BmpTabla;
}
Edit: I just changed the picture and worked fine.
Drop TImage component to the form, send it to back of the all controls, set the Align property to alClient.
In runtime
Image1->Picture->LoadFromFile("board.bmp");
The easiest way to have a custom background is to use a client-aligned TImage, like #serge suggested.
Another way is to load the BMP image into a Graphics::TBitmap object (like you are already attempting to do) and then use the Form's OnPaint event to draw the TBitmap onto the Form's Canvas.
The "image is not valid" error means you are trying to load a .bmp file that is not a valid BMP image. Double check the contents of the file.

Qt - QPixmap converts png to gray scale?

In Qt I used the following method to load images and set them as the background of QLabels:
QPixmap *pixmap= new QPixmap("home\\Images\\circle.png");
ui->cell11_Image->setPixmap(*pixmap);
ui->cell11_Image->setMask(pixmap->mask());
ui->cell11_Image->show();
delete(pixmap);
With the following result
The thing is: the images are in grayscale. However, here is one of the images
Does anyone know what is going on?
I think your label or one of parent widget is disable. Try to enable and check.

How to render QGraphicsScene animations out to a movie file?

Does anybody know how to render an animation from QGraphicsView / QGraphicsScene out to a movie file format (AVI, MPG, MP4, MOV, something) on disk? I've seen examples for rendering the scene out to an image file with QPrinter. Any ideas on if rendering animations to movies is possible?
I suppose worst case would be to step frame-by-frame and save images, then combine the images into a movie with some external tool... Any better suggestions? Is it possible to do this from QT directly somehow?
Thanks!
- Brian
I think one of the ways is to use QPixmap for capturing the images,
QPixmap pixMap = QPixmap::grabWidget(view);
Use QPixmap::toImage() to convert it to QImage.
And using QtFFmpegWrapper for creating the video directly from QImage.
You do not need to use an external tool. Just an external library.

Newbie: Minimal program to display a PNG in a window

All,
I must have a fundamental neuron missing, but I cannot get a simple program to load a PNG file and display it in a window. I'm not sure if it is a QPixmap, a QPicture, or what. All of the samples in the QTCreator are a bit more than I need right now. Baby steps...
I can get the window to display, and the program doesn't barf when I try to load the PNG, but it never gets displayed.
If someone would post a simple program to load a PNG from a file and display it, it would greatly appreciated. (I know, asking a lot, but...).
Thanks!
:bp:
this example is minimal: http://doc.trolltech.com/4.6/widgets-imageviewer.html
You will want to have a look at the function ImageViewer::open():
Build a QImage object from a filename;
Convert your QImage to a QPixmap with QPixmap::fromImage();
Put your QPixmap in a QLabel with QLabel::setPixmap().
The QImage object will automatically chose an appropriate reader according to the format of the image it detects in step 1.