.jpg as a background on gui

1 visualización (últimos 30 días)
Phillip Wolfe
Phillip Wolfe el 2 de Mzo. de 2015
Comentada: Image Analyst el 3 de Mzo. de 2015
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])

Respuestas (2)

Giorgos Papakonstantinou
Giorgos Papakonstantinou el 2 de Mzo. de 2015
Editada: Giorgos Papakonstantinou el 2 de Mzo. de 2015
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 comentarios
Phillip Wolfe
Phillip Wolfe el 3 de Mzo. de 2015
Editada: Phillip Wolfe el 3 de Mzo. de 2015
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
Giorgos Papakonstantinou el 3 de Mzo. de 2015
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.

Iniciar sesión para comentar.


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

Iniciar sesión para comentar.

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by