Working with images

To add an image, call the IDrawingService addImage() method with IDrawingInputBuilder:

Usage example

import com.intechcore.scomponents.scell.api.init.ScellApiEntryPoint;
import com.intechcore.scomponents.scell.api.spreadsheet.IScellCoreApiFactory;
import com.intechcore.scomponents.scell.api.spreadsheet.model.IWorkbook;
import com.intechcore.scomponents.scell.api.spreadsheet.model.IWorksheet;
import com.intechcore.scomponents.scell.api.spreadsheet.service.IValueService;

public class ImageExample {
    public static void main(String[] args) {
        ScellApiEntryPoint.getApiResolverAsync().thenAccept(apiResolver -> {

            IScellCoreApiFactory apiProvider = apiResolver.resolve(IScellCoreApiFactory.class);

            IWorkbook workbook = apiProvider.createNew();
            Logger logger = apiResolver.resolve(ILoggerFactory.class).getLogger(ImageExample.class);
            IWorksheet worksheet = workbook.getFirst();
            byte[] imageRaw;
            try {
                imageRaw = Files.readAllBytes(Paths.get(
                        ImageExample.class.getClassLoader().getResource("icons/add.png").toURI()));
            } catch (IOException | URISyntaxException e) {
                logger.error("Image content read error", e);
                return;
            }

            IDrawingService drawingService = worksheet.getImageService();

            try {
                drawingService.addImage(
                        apiResolver.resolve(IDrawingInputBuilder.class)
                                .fromCell(3, 3)              // set start anchor cell
                                .fromCellWithOffset(2, 3)    // set start anchor cell offset, points
                                .setDesiredWidth(345)        // decrease image's size
                                .setDesiredHeight(460.5)
                                .setContent(imageRaw)
                                .build());
            } catch (IOException e) {
                e.printStackTrace();
            }

            workbook.getWriter().fileName("imageExample.xlsx", true).save();

        }).join();
    }
}