Results 1 to 3 of 3
- 12-01-2010, 07:58 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Serializing BufferedImage with keeping transparency
Hi,
I serialize BufferedImage by using this class:
public class ServerUserAvatarMessage extends ServerMessage {
private static final long serialVersionUID = 6796478081410599600L;
private boolean success = false;
private boolean useDefaultAvatar = true;
private String username = null;
int width; int height; int[] pixels;
public void setAvatar(BufferedImage bi) {
width = bi.getWidth();
height = bi.getHeight();
pixels = new int[width * height];
int[] tmp = bi.getRGB(0, 0, width, height, pixels, 0, width);
}
/**
* @return the avatar
*/
public BufferedImage getAvatar() {
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bi.setRGB(0, 0, width, height, pixels, 0, width);
return bi;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the success
*/
public boolean isSuccess() {
return success;
}
/**
* @param success the success to set
*/
public void setSuccess(boolean success) {
this.success = success;
}
/**
* @return the useDefaultAvatar
*/
public boolean isUseDefaultAvatar() {
return useDefaultAvatar;
}
/**
* @param useDefaultAvatar the useDefaultAvatar to set
*/
public void setUseDefaultAvatar(boolean useDefaultAvatar) {
this.useDefaultAvatar = useDefaultAvatar;
}
}
But if i send png files using transparency, transparency is not displayed by the output file. :(
- 12-02-2010, 04:16 AM #2
Member
- Join Date
- Jun 2010
- Posts
- 28
- Rep Power
- 0
Your getAvatar method returns a BufferedImage that doesn't support transparency. That's probably the problem.
On a side note, I think most people would probably encode the BufferedImage into any one of the available formats (jpeg, png, gif, ect...) and save/send the encoded byte[] array instead of saving/sending the int[] rgb array. The space requirements of images in raw format (read: the int[] rgb array) is not a thing you should underestimate.Last edited by Maxideon; 12-02-2010 at 04:20 AM.
- 12-15-2010, 07:49 PM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Similar Threads
-
Alternating Transparency Based on Double Variable
By YellowPainting in forum Java 2DReplies: 2Last Post: 11-05-2010, 08:59 PM -
Keeping data in memory
By roud9 in forum New To JavaReplies: 1Last Post: 11-02-2010, 12:28 AM -
ImageIcon Transparency
By Lingerz in forum New To JavaReplies: 2Last Post: 06-04-2010, 02:53 PM -
Setting an image's transparency?
By aaroffl in forum AWT / SwingReplies: 1Last Post: 12-03-2008, 12:01 PM -
Creating a non-rectangular shell to simulate transparency
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:26 PM


LinkBack URL
About LinkBacks

Bookmarks