本文整理汇总了C++中QContent::open方法的典型用法代码示例。如果您正苦于以下问题:C++ QContent::open方法的具体用法?C++ QContent::open怎么用?C++ QContent::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QContent
的用法示例。
在下文中一共展示了QContent::open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: thumbnail
QImage ExifContentPlugin::thumbnail( const QContent &content, const QSize &size, Qt::AspectRatioMode mode )
{
QImage image;
QIODevice *device = content.open();
if (device) {
QExifImageHeader exif;
if (exif.loadFromJpeg(device)) {
image = exif.thumbnail();
if (!image.isNull() && size.isValid())
image = image.scaled(size, mode, Qt::SmoothTransformation);
}
device->close();
delete device;
}
return image;
}
示例2: thumbnail
/*!
Loads a thumbnail representation of \a content. The thumbnail will be scaled to \a size
according to the given aspect ratio mode.
*/
QImage QContentStore::thumbnail(const QContent &content, const QSize &size, Qt::AspectRatioMode mode)
{
QImage thumbnail;
QString thumbPath = thumbnailPath(content.fileName());
QFileInfo thumbInfo(thumbPath);
if (thumbInfo.exists()) {
if (thumbInfo.lastModified() > content.lastUpdated())
thumbnail = readThumbnail(thumbPath, size, mode);
} else {
thumbnail = QContentFactory::thumbnail(content, size, mode);
}
if (thumbnail.isNull()) {
if (QIODevice *device = content.open()) {
QImageReader reader(device);
if (reader.canRead()) {
QSize scaledSize = reader.size();
reader.setQuality(25);
if (scaledSize.width() > 128 || scaledSize.height() > 128) {
scaledSize.scale(QSize(128, 128), Qt::KeepAspectRatio);
reader.setQuality( 49 ); // Otherwise Qt smooth scales
reader.setScaledSize(scaledSize);
reader.read(&thumbnail);
if (!thumbnail.isNull()) {
QImageWriter writer(thumbPath, QByteArray::fromRawData("PNG", 3));
writer.setQuality(25);
writer.write(thumbnail);
if (size.isValid())
thumbnail = thumbnail.scaled(size, mode);
}
} else {
if (size.isValid()) {
scaledSize.scale(size, mode);
reader.setQuality( 49 ); // Otherwise Qt smooth scales
reader.setScaledSize(scaledSize);
}
reader.read(&thumbnail);
}
}
delete device;
}
}
if (thumbnail.isNull() && content.type().startsWith(m_audioPrefix)) {
QDir dir = QFileInfo(content.fileName()).absoluteDir();
foreach (const QString &fileName, m_folderThumbnails) {
if (dir.exists(fileName)) {
thumbnail = readThumbnail(dir.absoluteFilePath(fileName), size, mode);
break;
}
}
}
示例3: takePhotoNow
void CameraMainWindow::takePhotoNow()
{
QImage img = camera->videocaptureview->image();
if ( snapRequest != 0 ) {
// Rescale the image and pop it into a QDSData object
QImage scaledimg = img.scaled( snap_max,
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
QByteArray savedImageData;
{
QDataStream stream( &savedImageData, QIODevice::WriteOnly );
stream << QPixmap::fromImage( scaledimg );
}
QDSData snappedImage( savedImageData, QMimeType( "image/x-qpixmap" ) );
// Send response with the data
snapRequest->respond( snappedImage );
// Reset snap mode
setSnapMode( false );
delete snapRequest;
snapRequest = 0;
// Finished serving QDS request so close the application
close();
hideWaitScreen();
} else {
showWaitScreen();
QContent f;
QList<QString> c;
f.setType("image/jpeg");
f.setName(tr("Photo, %1","date")
.arg(QTimeString::localYMDHMS(QDateTime::currentDateTime(),QTimeString::Short)));
f.setMedia( settings->location->documentPath() );
c.append(camcat);
f.setCategories(c);
QIODevice* contentDevice = f.open(QIODevice::WriteOnly);
if (contentDevice != 0)
{
QImage temp = img.convertToFormat(QImage::Format_RGB32);
temp.save(contentDevice, "JPEG", pquality);
contentDevice->close();
f.commit();
pushThumb(f, img);
hideWaitScreen();
}
else
{
QString errorText = f.errorString();
if (errorText.isEmpty())
errorText = tr("Unknown error");
QMessageBox::warning(0,
tr("Error saving photo"),
tr("Could not save photo: %1").arg(errorText));
}
}
preview();
}