transparency in DefineBitsJPEG3 and 4

This commit is contained in:
Jindra Petk
2013-05-04 15:03:32 +02:00
parent 8d3272742e
commit 6bb2cb228d
2 changed files with 32 additions and 4 deletions

View File

@@ -68,13 +68,27 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
@Override
public String getImageFormat() {
return ImageTag.getImageFormat(imageData);
String fmt=ImageTag.getImageFormat(imageData);
if(fmt.equals("jpg")){
fmt = "png"; //transparency
}
return fmt;
}
@Override
public BufferedImage getImage(List<Tag> tags) {
try {
return ImageIO.read(new ByteArrayInputStream(imageData));
BufferedImage img=ImageIO.read(new ByteArrayInputStream(imageData));
BufferedImage img2=new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
for(int y=0;y<img.getHeight();y++){
for(int x=0;x<img.getWidth();x++){
int val=img.getRGB(x, y);
int a = bitmapAlphaData[x+y*img.getWidth()]&0xff;
val = (val&0xffffff) | (a<<24);
img2.setRGB(x, y, val);
}
}
return img2;
} catch (IOException ex) {
}
return null;

View File

@@ -51,7 +51,11 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
@Override
public String getImageFormat() {
return ImageTag.getImageFormat(imageData);
String fmt=ImageTag.getImageFormat(imageData);
if(fmt.equals("jpg")){
fmt = "png"; //transparency
}
return fmt;
}
@Override
@@ -79,7 +83,17 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
@Override
public BufferedImage getImage(List<Tag> tags) {
try {
return ImageIO.read(new ByteArrayInputStream(imageData));
BufferedImage img=ImageIO.read(new ByteArrayInputStream(imageData));
BufferedImage img2=new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
for(int y=0;y<img.getHeight();y++){
for(int x=0;x<img.getWidth();x++){
int val=img.getRGB(x, y);
int a = bitmapAlphaData[x+y*img.getWidth()]&0xff;
val = (val&0xffffff) | (a<<24);
img2.setRGB(x, y, val);
}
}
return img2;
} catch (IOException ex) {
}
return null;