Page 1 of 1

couldn't open NEF files from Nikon d5100

Posted: 2014-02-01T13:51:41-07:00
by rwikee
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.

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());


}



Re: couldn't open NEF files from Nikon d5100

Posted: 2014-02-01T14:03:35-07:00
by snibgo
Can you do it from the command line?

Code: Select all

convert x.NEF out.jpg
If not, then does dcraw work?

Code: Select all

dcraw x.NEF

Re: couldn't open NEF files from Nikon d5100

Posted: 2014-02-01T14:59:05-07:00
by Bonzo
If you are having a problem start with something simple first and as snibgo says try in the command line or write a bit of code that opens a NEF files and saves it without all the other code.

Just skipping through the 11 pages of search for NEF and most people open them OK but there was a post in 2008 about a new NEF format. I think you need to tell us the IM version you are using.