How to add more images on a gui...

조회 수: 1 (최근 30일)
Jethro
Jethro 2011년 12월 3일
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!

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 3일
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
Jethro
Jethro 2011년 12월 3일
Why when I wrote axes1=axes... like you, there's an error?? o.O
Chandra Kurniawan
Chandra Kurniawan 2011년 12월 3일
What is the error message??

댓글을 달려면 로그인하십시오.


Jethro
Jethro 2011년 12월 3일
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
Jethro
Jethro 2011년 12월 3일
Yes, it's a .fig file, I'm sending you everything!
Jethro
Jethro 2011년 12월 3일
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 ;)

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 12월 4일
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