.jpg as a background on gui

1 view (last 30 days)
Phillip Wolfe
Phillip Wolfe on 2 Mar 2015
Commented: Image Analyst on 3 Mar 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])

Answers (2)

Giorgos Papakonstantinou
Giorgos Papakonstantinou on 2 Mar 2015
Edited: Giorgos Papakonstantinou on 2 Mar 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 Comments
Giorgos Papakonstantinou
Giorgos Papakonstantinou on 3 Mar 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.

Sign in to comment.


Image Analyst
Image Analyst on 3 Mar 2015
  2 Comments
Image Analyst
Image Analyst on 3 Mar 2015
I don't know. I've never tried it but I doubt it. I think fill just fills with a uniform color.

Sign in to comment.

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!