couldn't open NEF files from Nikon d5100
Posted: 2014-02-01T13:51:41-07:00
I am writing a simple image viewer using qt. I can open the NEF files using qimage , but couldn't do so using imagemagick.
here is the code i am using . It is working for many formats. But for NEF format , it throws exception and returns.
here is the code i am using . It is working for many formats. But for NEF format , it throws exception and returns.
Code: Select all
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setupSignals();
source.clear();
ui->label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->label->setScaledContents(true);
ui->scrollArea->setAcceptDrops(false);
setAcceptDrops(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent *event)
{
QList<QUrl> urls = event->mimeData()->urls();
if (urls.isEmpty())
return;
QString fileName = urls.first().toLocalFile();
if (fileName.isEmpty())
return;
displayImage(fileName);
// if (readFile(fileName))
setWindowTitle(tr("%1 - %2").arg(fileName)
.arg(tr("Drag File")));
}
void MainWindow::displayImage(QString fileName)
{
source = fileName;
QImage tempImage;
try
{
tempImage.load(fileName);
//pic.read( qPrintable(fileName));
}
catch(Exception &error)
{
return;
}
// pic.magick("XPM");
// pic.write(&blob);
// imgData = ((char*)(blob.data()));
// pixmap.loadFromData(imgData, "XPM");
ui->label->setPixmap(QPixmap::fromImage(tempImage));
}
void MainWindow::adjustScrollBar(QScrollBar *scrollBar, double factor)
{
scrollBar->setValue(int(factor * scrollBar->value()
+ ((factor - 1) * scrollBar->pageStep()/2)));
}
void MainWindow::setupSignals()
{
connect(ui->actionTo_jpeg_high, SIGNAL(triggered()), this, SLOT(saveHigh()));
connect(ui->actionTo_jpeg_Mail, SIGNAL(triggered()), this, SLOT(saveLow()));
}
void MainWindow::saveHigh()
{
if(source == NULL)
return;
try
{
pic.read( qPrintable(source));
}
catch(Exception &error)
{
return;
}
QString path = source.left(source.lastIndexOf("/"));
pic.magick("JPEG");
path += "/a.jpeg";
pic.write(path.toStdString());
}
void MainWindow::saveLow()
{
if(source == NULL)
return;
try
{
pic.read( qPrintable(source));
}
catch(Exception &error)
{
return;
}
QString path = source.left(source.lastIndexOf("/"));
pic.magick("JPEG");
pic.quality(40);
path += "/a.jpeg";
pic.write(path.toStdString());
}