How to add more images on a gui...
1 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Chandra Kurniawan
2011-12-4
Hello,,
Here the download link. I cannot modified your code, but I created new fig file.
3 个评论
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 :)
更多回答(3 个)
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');
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')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!