How to change background color of an image in a GUI

조회 수: 7 (최근 30일)
Rocco Didio
Rocco Didio 2019년 9월 11일
댓글: Rocco Didio 2019년 9월 12일
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);

채택된 답변

Cris LaPierre
Cris LaPierre 2019년 9월 11일
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
Cris LaPierre
Cris LaPierre 2019년 9월 12일
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);
Rocco Didio
Rocco Didio 2019년 9월 12일
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by