.jpg as a background on gui

1 次查看(过去 30 天)
Phillip Wolfe
Phillip Wolfe 2015-3-2
I have a code that creates a projectile motion. I'm looking to make the background a .jpg file instead of colors that I currently use. Help is much appreciated. This is our current background.
backgroundX = [0 1 2 3 4 5 6 7 8 9 10 0];
backgroundY = [0 4 2 7 5 8 3 4 2 5 0 0];
backgroundX1 = [0 .75 1.5 2 2.8 3.5 4 4.666667 5.2 6 6.5 7.25 8,...
8.66667 9.2 10 0];
backgroundY1 = [0 3 3 2 6 6 5 7 7 3 3.5 3.5 2 4 4 0 0];
backgroundX2 = [0 0 1 2 3 4 5 6 7 8 9 10 10 0];
backgroundY2 = [10 0 4 2 7 5 8 3 4 2 5 0 10 10];
fill(330*backgroundX,200*backgroundY,'PhilSkyline.jpg')
fill(330*backgroundX1,200*backgroundY1,[0 .65 0])
fill(330*backgroundX2,200*backgroundY2,[.3 .7 1])
axis([0 3300 0 2000])

回答(2 个)

Giorgos Papakonstantinou
编辑:Giorgos Papakonstantinou 2015-3-2
You can create a figure and remove the MenuBar. In this figure you can display your image, whose parent is an axis. You can set the axis position to occupy the full dimension of your figure.
i.e.
fig = figure('MenuBar', 'none');
IM = imread('peppers.png');
h = image(IM);
set(get(h, 'parent'),'XTick', [], 'YTick', [], 'position' , [0 0 1 1])
  2 个评论
Phillip Wolfe
Phillip Wolfe 2015-3-3
编辑:Phillip Wolfe 2015-3-3
This is the entire for loop. The last suggestion didn't work
for t = (0:0.1:t_Total)
xx = v0*cosd(theta)*t; % displacement in x direction as the object
% progresses through the time interval. Note: there is no
% acceleration in the x direction
yy = y0 + ((v0*sind(theta)*t) + (0.5*g*(t*t))); % dispalcement in the
% y direction as the object progresses through the time interval
pause(0.01) % causes slight pause before continuing
phi = spin*t;
rotationFactorX = [cos(phi), -sin(phi)];
rotationFactorY = [sin(phi), cos(phi)];
% Translating the roation point to the origin
originx = shapeX - .5;
originy = shapeY - .5;
% Rotating the Object
rotatex = (rotationFactorX*[originx;originy]);
rotatey = (rotationFactorY*[originx;originy]);
% Translating the object back
moveBackx = rotatex+.5;
moveBacky = rotatey+.5;
% Displacement of Object
x1 = moveBackx;
y1 = moveBacky;
% Background
hold on
fig = figure('MenuBar','none');
IM = imread('PhilSkyline.jpg');
h = image(IM);
set(get(h, 'parent'),'XTick', [], 'YTick', [], 'position' , [0 0 4 4]);
axis([0 2000 0 2000])
axis equal
shape = fill((s*x1)+xx,(s*y1)+yy,color);
hold off
end
Giorgos Papakonstantinou
The limits of your axis are the same size of your image. Therefore when you invoke the|axis| command you change the limits of the axis: [xmin xmax ymin ymax]. You set them [0 2000 0 2000].
Is this size of your image? (2000 x 2000).
Moreover, when you issue axis equal you set the aspect ratio so that the data units are the same in every direction. As a result your image does not fill the whole figure when you resize the figure.

请先登录,再进行评论。


Image Analyst
Image Analyst 2015-3-3
  2 个评论
Phillip Wolfe
Phillip Wolfe 2015-3-3
Is there any way to use the fill command to set the jpg as the background?
Image Analyst
Image Analyst 2015-3-3
I don't know. I've never tried it but I doubt it. I think fill just fills with a uniform color.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by