Compiling err with images

I have matlab gui that uses a splash screen using splash function... The gui worked very well inside matlab but after compiling i get an error,which says 'theimage.png' does'nt exist...please help me out

回答(2 个)

Walter Roberson
Walter Roberson 2012-8-19

0 个投票

Did you "add" the .jpg to the executable? You need to specifically tell the builder to include it along with the executable.
See also the documentation for ctfroot
When after compiling? Right after you compile it? Or when you run the program. I'll assume you mean when you try to run the compiled app. You should specify the full path of the image, and check if it exists so that your app doesn't crash:
folder = 'C:\WhateverFolderYouWant'
baseFileName = 'theimage.png';
fullFileName = fullfile(folder, baseFileName);
if exist(fullFileName, 'file')
% Found splash image, so display it.
splashImage = imread(fullFileName);
imshow(splashImage);
else
% Didn't find it there, so now look in the current folder.
folder = pwd; % This should be the same as ctfroot if you just started the app.
fullFileName2 = fullfile(folder, baseFileName);
if exist(fullFileName2, 'file')
message = sprintf('Warning: could not find splash image:\n%s or \n', ...
fullFileName, fullFileName2);
uiwait(warndlg(message));
end
end
At least this code will tell you where the program is looking for the spalsh image file. I think you probably shipped the file and saved it in the same folder as the executable, but you don't realize that the executable is not the real executable and that it's just an archive. It runs that exe and unpacks the real exe to some secret folder - ctfroot. You can put ctfroot on its own line or in a fprintf statement to find out where it hid your real executable. You would have to put your executable there, if you installed it yourself, or else use deploy tool and make sure you bundle that image in with your executable so that it will find it in the ctfroot folder. I know, I know - it's confusing. I don't know why they do it that way but they do.

类别

帮助中心File Exchange 中查找有关 Setup and Configuration 的更多信息

标签

提问:

2012-8-19

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by