How to change background color of an image in a GUI

8 views (last 30 days)
I want to insert an image (an arrow) on a button. I created the arrow in PowerPoint without background and then I saved that as image file. When I upload the image on the button it creates a white background. Can I substitute the white pixels with grey ([0.8 0.8 0.8]) pixels?
That's the code I use to upload the image
[a,map]=imread('arrow.jpg');
[r,c,d]=size(a);
x=ceil(r/100);
y=ceil(c/100);
g=a(1:x:end,1:y:end,:);
g(g==255)=5.5*255;
set(handles.btn,'CData',g);

Accepted Answer

Cris LaPierre
Cris LaPierre on 11 Sep 2019
If you can save your image as a png instead, see this post about displaying png images with transparent backgrounds.
Even with a png, images get displayed in an axes. Even if the image doesn't have a background, it will at least originally display in an axes with a background color set to white. You can turn that off using
axis off
of
set(gca,'Color','none')
  4 Comments
Cris LaPierre
Cris LaPierre on 12 Sep 2019
You are doing image and imshow. Both display an image, but imshow does not accept the transparency settings. Can you make this work with just image(A,'AlphaData',transparency);

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!