Transparent error changed to Opaque picture


#1

Mac OS 10.14.4
java version “1.8.0_181”
Java™ SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot™ 64-Bit Server VM (build 25.181-b13, mixed mode)
Aspose: aspose-cells-19.7

Read Images From orignal Excel File, then New excel file and add images to sheet
The images from orignal files are translucent, but after added to new file ,they become opaque
excels.zip (283.1 KB)

ImageInfo.java

public class ImageInfo implements Serializable {
   private int index;
   private String name;
   private boolean hidden;
   private int zPosition;
   private byte[] data;
   private float[] position;

   public int getIndex() {
      return index;
   }

   public void setIndex(int index) {
      this.index = index;
   }

   public boolean isHidden() {
       return hidden;
   }

  public void setHidden(boolean hidden) {
       this.hidden = hidden;
  }

  public String getName() {
       return name;
  }

  public void setName(String name) {
      this.name = name;
  }

  public byte[] getData() {
      return data;
  }

  public void setData(byte[] data) {
      this.data = data;
  }

  public float[] getPosition() {
      return position;
  }

  public void setPosition(float[] position) {
      this.position = position;
  }

  public int getzPosition() {
      return zPosition;
  }

  public void setzPosition(int zPosition) {
      this.zPosition = zPosition;
  }
}

Read File

Workbook workbook = new Workbook(****FilePath****);
WorksheetCollection sheetCollection = workbook.getWorksheets();
Worksheet worksheet = sheetCollection.get(0);
ArrayList<ImageInfo> imageInfos = new ArrayList<>();
PictureCollection pictureCollection = worksheet.getPictures();
int pictureCount = pictureCollection.getCount();
for (int picIndex = 0; picIndex < pictureCount; picIndex++) {
      Picture picture = pictureCollection.get(picIndex);
      ImageInfo imageInfo = new ImageInfo();
      imageInfo.setIndex(picIndex);
      imageInfo.setData(picture.getData());
      imageInfo.setName(picture.getName());
      float left = picture.getLeftToCorner();
      float top = picture.getTopToCorner();
      float width = picture.getWidth();
      float height = picture.getHeight();
      imageInfo.setPosition(new float[]{top, left, width, height});
      imageInfo.setHidden(picture.isHidden());
      imageInfo.setzPosition(picture.getZOrderPosition());
      imageInfos.add(imageInfo);
 }

Export File
Write Images to New Excel

   Workbook workbook = new Workbook();
   WorksheetCollection worksheets = workbook.getWorksheets();
   Worksheet worksheet = worksheets.get(0);
   for (ImageInfo imageInfo : imageInfos) {
        int index = worksheet.getPictures().add(1, 1, new ByteArrayInputStream(imageInfo.getData()));
        Picture picture = worksheet.getPictures().get(index);
        if (imageInfo.getName()!=null){
             picture.setName(imageInfo.getName());
        }
       picture.setTopToCorner((int) imageInfo.getPosition()[0]);
       picture.setLeftToCorner((int) imageInfo.getPosition()[1]);
       picture.setWidth((int) imageInfo.getPosition()[2]);
       picture.setHeight((int) imageInfo.getPosition()[3]);
       picture.setHidden(imageInfo.isHidden());
       picture.setZOrderPosition(imageInfo.getzPosition());
   }

#2

@JamesGuo,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-42980 – Transparent image changes to opaque during picture copy

#3

thanks, i also found that they can somethime be switched by set transparent color in wps
1565762902454.jpg (474.6 KB)


#4

@JamesGuo,
Thank you for the additional information. We will consider it while analysing this issue.


#5

@JamesGuo,

Please set the FormatPicture.TransparentColor of the shape:
e.g
Sample code:

CellsColor color = workbook.createCellsColor();
color.setColor(Color.getWhite());
shape.getFormatPicture().setTransparentColor(color);

And we will provide you fix soon, then you can simply use ShapeCollection.addCopy() to copy the shape from other file.


#6

The issues you have found earlier (filed as CELLSJAVA-42980) have been fixed in Aspose.Cells for Java v19.8. This message was posted using BugNotificationTool from Downloads module by ahsaniqbalsidiqui