How to change background color of an image in a GUI
8 views (last 30 days)
Show older comments
Rocco Didio
on 11 Sep 2019
Commented: Rocco Didio
on 12 Sep 2019
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);
0 Comments
Accepted Answer
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
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);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!