How to add more images on a gui...

1 visualizzazione (ultimi 30 giorni)
Jethro
Jethro il 3 Dic 2011
Hello everybody!
I'm working on a project, and I created a first window for choosing language. I already added a background image using axes
axes(hObject)
imshow('Img_name.png');
Now I have to add some flags. I tried the same way with new axes spaces, also tried to bring them to front, but there's no results. For each flag I used the same code, changing the Img_name... I tried to change "hObject" using other handles, but something's wrong...
I already tried with
image('Img_name.png')
and
imagesc('Img_name.png')
and I'm sure Matlab can read png files (the background is a png image) Any ideas?? Thanks!

Risposta accettata

Chandra Kurniawan
Chandra Kurniawan il 4 Dic 2011
Hello,,
Here the download link. I cannot modified your code, but I created new fig file.
  3 Commenti
Chandra Kurniawan
Chandra Kurniawan il 4 Dic 2011
It just to turns off all axis lines, tick marks, and labels.
Coz command 'imagesc' make axis line turned on :)
Jethro
Jethro il 4 Dic 2011
Ok thanks for your explanation! ;)

Accedi per commentare.

Più risposte (3)

Chandra Kurniawan
Chandra Kurniawan il 3 Dic 2011
Hello,
I think what's wrong with using 'imagesc' function to display your images?
Imagesc works for all supported image formats (.png, .jpg, .tiff, .bmp, etc).
I just do the same way with you and all of my image can be displayed with command 'imagesc'.
clear; clc;
hfig = figure('unit','pixel','position',[100 100 620 400]);
axes1 = axes('parent',hfig,'unit','pixel','position',[10 10 600 380]);
axes2 = axes('parent',hfig,'unit','pixel','position',[20 20 100 100]);
axes3 = axes('parent',hfig,'unit','pixel','position',[140 20 100 100]);
axes4 = axes('parent',hfig,'unit','pixel','position',[260 20 100 100]);
axes5 = axes('parent',hfig,'unit','pixel','position',[380 20 100 100]);
axes6 = axes('parent',hfig,'unit','pixel','position',[500 20 100 100]);
I = imread('peppers.png');
J = imread('fabric.png');
K = imread('gantrycrane.png');
L = imread('hestain.png');
M = imread('pears.png');
N = imread('tape.png');
imagesc(I,'parent',axes1); axis(axes1,'off');
imagesc(J,'parent',axes2); axis(axes2,'off');
imagesc(K,'parent',axes3); axis(axes3,'off');
imagesc(L,'parent',axes4); axis(axes4,'off');
imagesc(M,'parent',axes5); axis(axes5,'off');
imagesc(N,'parent',axes6); axis(axes6,'off');
  2 Commenti
Jethro
Jethro il 3 Dic 2011
Why when I wrote axes1=axes... like you, there's an error?? o.O
Chandra Kurniawan
Chandra Kurniawan il 3 Dic 2011
What is the error message??

Accedi per commentare.


Jethro
Jethro il 3 Dic 2011
I post you the code I wrote
function Background_LAN_CreateFcn(hObject, eventdata, handles)
axes(hObject)
imshow('Image.png');
TitleText=text (87, 220, 'Text1');
set(TitleText, 'Color', [1 1 1], 'FontSize', 14);
LanguageText1=text (400, 270, 'Text2');
set(LanguageText1, 'Color', [1 1 1], 'FontSize', 14);
LanguageText2=text (400, 300, 'Text3');
set(LanguageText2, 'Color', [1 1 1], 'FontSize', 12);
This part sets the background
Now I have
function IT_Flag_CreateFcn(hObject, eventdata, handles)
To set with the image... I tried in every way possible... But when my program runs, I can see EVERYTHING except my flag...
  3 Commenti
Jethro
Jethro il 3 Dic 2011
Yes, it's a .fig file, I'm sending you everything!
Jethro
Jethro il 3 Dic 2011
I forgot to say sometimes my tags are deleted but I don't know how o.O So, you can set it again from the .m file ;)

Accedi per commentare.


Walter Roberson
Walter Roberson il 4 Dic 2011
image() and imagesc() do not accept filenames. You have to pass the image data itself to image() and imagesc(), having read in the image before that using imread()
imshow() does allow filenames and will read in the file for you. If you want imshow() to display on a particular axes, then you need to use the 'Parent' parameter, as in
imshow('Img_name.png', 'Parent', hObject);
Remember that at some point before you add the new image, you must "hold" the axes or else the new image will remove the previous ones.
hold(hObject, 'on')

Community Treasure Hunt

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

Start Hunting!

Translated by