Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) QPixmapExample1

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppQPixmapExample1/CppQPixmapExample1.pro

 

win32 {
  # Windows only
  message("Console application, built for Windows")
  QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
}

macx {
  # Mac only
  message("Console application, built for Mac")
  QMAKE_CXXFLAGS = -mmacosx-version-min=10.7 -std=gnu0x -stdlib=libc+
  CONFIG +=c++11
}

unix:!macx{
  # Linux only
  message("Console application, built for Linux")
  QMAKE_CXXFLAGS += -Werror
  QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
}

cross_compile {
  # Crosscompile only
  message("Console application, cross-compiling from Linux to Windows")
  QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
}


# Go ahead and use Qt.Core: it is about as platform-independent as
# the STL and Boost
QT += core

# Go ahead and use Qt.Gui: it is about as platform-independent as
# the STL and Boost. It is needed for QImage
QT += gui

# Don't define widgets: it would defy the purpose of this console
# application to work non-GUI
#greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

#
#
# Type of compile
#
#

CONFIG(release, debug|release) {
  DEFINES += NDEBUG NTRACE_BILDERBIKKEL
}

SOURCES += main.cpp

 

 

 

 

 

./CppQPixmapExample1/main.cpp

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <QImage>
#include <QPixmap>
#pragma GCC diagnostic pop

QPixmap CreatePixmap(const int width, const int height, const int z)
{
  QPixmap pixmap(width,height);
  QImage image = pixmap.toImage();
  for (int y=0;y!=height;++y)
  {
    for (int x=0;x!=width;++x)
    {
      image.setPixel(
        QPoint(x,y), //Position
        qRgb((x+z+0)%256,(y+z+0)%256,(x+y+z)%256) //Color

        /*
        QColor( //Color
          (x+z+0)%256,
          (y+z+0)%256,
          (x+y+z)%256)
        .rgb()
        */
      );
    }
  }
  pixmap = QPixmap::fromImage(image);
  return pixmap;
}

int main()
{
  //Cannot create a QPixmap here, because of the following error:
  //
  //  QPixmap: Must construct a QApplication before a QPaintDevice
  //

  //QPixmap pixmap = CreatePixmap(32,32,128);

  //pixmap.save("CppQPixmapExample1.png");
  //QImage image = pixmap.toImage();
  //image.save("CppQPixmapExample1.png");


}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml