GUI: how to insert png image with original resolution and transparent background?

조회 수: 2 (최근 30일)
I found that inserting images is done by the axes object. I can show the image (16x16 pixels) in my GUI, but it's always magnified, and the transparent background is rendered black. How can I fix this?
Thanks!

답변 (1개)

Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 8월 31일
To keep your image in its original scale, you have include the following line just after the one where you display the image in the axes (with image, imagesc or imshow):
axis image;
Regarding the transparent background, I suggest you to take a look at this MATLAB Newsgroup thread. I think your question is answered here.
  댓글 수: 2
geomod
geomod 2011년 9월 1일
Hi Arturo,
With your hint the image still was not shown in its original resolution and correct height-width ratio. Eventually I could fix it by adjusting the Units property of the axes object to pixels and manually adjusting height and width under Position.
Thanks for the thread hint! It made me look for the alpha channel which seemed not available for the image I was using. With some simple image editing I colored the 'transparent' part of the image to the grey color of the GUI.
Regards
Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 9월 1일
Yes, your solution for keeping the image in its original scale would work, but it is not practical (suppose you change of image, you would have to do it again!).
Suppose you have the axes' handle in a variable called h. Try it this way:
axis(h, 'image')
Regarding the alpha channel issue, I am glad it worked ;-)

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

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by