Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
display java image with transparent background

Subject: display java image with transparent background

From: Jveer

Date: 25 Feb, 2009 16:54:02

Message: 1 of 4

when i use the following method to read and display a java image from a picture with transparent background, the transparent part of the background is always replaced by black background. can anyone please suggest a method around this problem?

I=imread(filename); % Reads image file

JImage=im2java(I);win=javax.swing.JWindow;
icon=javax.swing.ImageIcon(JImage);
label=javax.swing.JLabel(icon);win.getContentPane.add(label);

Subject: display java image with transparent background

From: Yair Altman

Date: 25 Feb, 2009 23:39:02

Message: 2 of 4

"Jveer " <jveer@jveer.com> wrote in message <go3t3a$mlb$1@fred.mathworks.com>...
> when i use the following method to read and display a java image from a picture with transparent background, the transparent part of the background is always replaced by black background. can anyone please suggest a method around this problem?
>
> I=imread(filename); % Reads image file
>
> JImage=im2java(I);win=javax.swing.JWindow;
> icon=javax.swing.ImageIcon(JImage);
> label=javax.swing.JLabel(icon);win.getContentPane.add(label);

This question is better asked in Java forums, not a Matlab forum...
Two initial hints:
 - try setting the image's alpha channel, which controls transparency
 - label.setOpaque(0), otherwise the label itself is non-transparent

or try Google: http://www.google.com/search?num=50&hl=en&q=java+create+transparent+image&btnG=Search

Yair Altman

Subject: display java image with transparent background

From: Jveer

Date: 25 Feb, 2009 23:56:02

Message: 3 of 4

> Yair Altman

thanks for the reply. well i posted it on this forum instead of a java one because this code is from matlab!!!! i'm using the java support to display frameless images.

i tried the label.setOpaque(0) but it had no effect. can you please explain how to use it properly to integrate it my code given above?

Subject: display java image with transparent background

From: Yair Altman

Date: 26 Feb, 2009 00:41:03

Message: 4 of 4

"Jveer " <jveer@jveer.com> wrote in message <go4lqi$73n$1@fred.mathworks.com>...
> > Yair Altman
>
> thanks for the reply. well i posted it on this forum instead of a java one because this code is from matlab!!!! i'm using the java support to display frameless images.
>
> i tried the label.setOpaque(0) but it had no effect. can you please explain how to use it properly to integrate it my code given above?

Jveer - your code is in Java. The fact that it runs in the Matlab environment does not change this fact. 99% of the responders on this forum do not know Java, so if you expect answers you need to get java developers to help you. You'll find that there are many active Java forums that can answer your question. Once you find out the answer in Java, then entering the java code in Matlab is easy.

Yair

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us