Namespaces
Variants
Actions

Reading big images in Qt

Jump to: navigation, search
Article Metadata

Tested with
SDK: Qt "Tower" pre-release
Devices(s): Nokia 5800 XpressMusic, Nokia N97, Nokia N900

Compatibility
Platform(s): Qt

Article
Keywords: QImageReader
Created: tepaa (24 Nov 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This example shows you how to load big images into memory using QImageReader.

Successive loading of big images with a large memory footprint using the QPixmap::load() method may sometimes fail due to RAM restrictions (detected with images taken with the device camera on Nokia 5800 XpressMusic or Nokia N97). To avoid this, you have to use QImageReader and set QImageReader::setScaledSize() for the reader before loading the image. The following code has been tested with JPEG images.

Preconditions

None

Source

QImageReader reader; 
 
// Set image name
reader.setFileName("mypicture.jpg");
 
// Read image current size
QSize imageSize = reader.size();
 
// Scale image to fit to screen
imageSize.scale(size(), Qt::KeepAspectRatio);
 
// Set wanted image size for reader
reader.setScaledSize(imageSize);
 
// Read image
QImage image = reader.read();
 
// Make QPixmap (if needed)
QPixmap pixmap = QPixmap::fromImage(image);


Postconditions

The device is able to read big JPEG images.


See also

This page was last modified on 11 October 2012, at 04:18.
241 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved