ofPixels and ofLoadImage problem

hi, I’m trying to load an image in an ofPixels object:

ofPixels p;
ofLoadImage(p, "path");

but the console gives me this: [ error ] ofPixels: allocate(): unknown image type, not allocating what it means?

the image is a .jpg file

Is your “path” a fully qualified path? If your path is not absolute (e.g. starts with / on *nix system or something like C:\ on a windows system) ofLoadImage will assume that you are loading an image from your data/bin folder in your app directory. Thus, you need to make sure that you image is in your YOUR_APP_DIR/bin/data/ folder.

Assuming that you have everything in the right place, can you open other jpg files? Perhaps try other formats like png, etc to make sure the file isn’t corrupt.

I take the path from dragInfo.files[0], so I think it’s not there the problem, the image is not corrupt because I can load it if I use ofImage::loadImage function…

Hmmm … can you post some code or a gist?

void testApp::dragEvent(ofDragInfo dragInfo){ 
    if(dragInfo.files.size() == 1) {
        ofLoadImage(pPhoto, dragInfo.files[0]);
        squarePhoto(&pPhoto);
        
        photo.readToPixels(pPhoto);
        pPhoto.resize(res*def, res*def);
        
        photoDragged = TRUE;
}
}

void testApp::squarePhoto(ofPixels *img) {
    int w = img->getWidth(), h = img->getHeight();
    
    if(w > h) img->crop(w/2 - h/2, 0, h, h);
    else if(h > w) img->crop(0, h/2 - w/2, w, w);
    
    if(img->getWidth()%res != 0) img->resize(img->getWidth()-(img->getWidth()%res), img->getWidth()-(img->getWidth()%res));
}

What is the output of std::cout << dragInfo.files[0] << std::endl;

What is the output of std::cout << ofToDataPath(dragInfo.files[0]) << std::endl;

Also, what oF version, operating system and windowing system are you using (GLFW … currently the default or GLUT pre 0.8.0 default)?

Both couts give me “/Users/andreagiampietro/Desktop/cartella senza titolo/_MG_0901.jpg”

I’m working on Mac OSX 10.6.8 and I generated the project with ProjectGenerator and I didn’t made any changes except for the startig window size

And what version of openFrameworks are you using?

I’ve tried your code locally and with the examples/utils/dragDropExample and it works just fine. Have you tried it with other jpeg images?

0.8… yes, I tried several images, but no one works T_T

I tried to restart XCode too, but nothing

Does the examples/utils/dragDropExample work for you?

The example works.

I’ve just tried this, the first time it gave me the same error, now it doesn’t and seems working…

void testApp::dragEvent(ofDragInfo info){
	
	if( info.files.size() > 0 ){
		std::cout << info.files[0] << std::endl;
        std::cout << ofToDataPath(info.files[0]) << std::endl;
        
        ofLoadImage(pPhoto, info.files[0]);
    }
}

well, I found that the problem is in “photo.readToPixels(pPhoto);”

where pPhoto is a ofPixels object and photo is a ofTexture object…

so the image is loaded… Sorry for the mistake

Great! Glad you got it resolved.