How to change background color of an image in a GUI

7 visualizaciones (últimos 30 días)
Rocco Didio
Rocco Didio el 11 de Sept. de 2019
Comentada: Rocco Didio el 12 de Sept. de 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);

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 11 de Sept. de 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 comentarios
Cris LaPierre
Cris LaPierre el 12 de Sept. de 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);

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by