POI插入图片的时候,使用resize函数还是变形的问题

在Excel2000上使用POI插入图片时,尽管调用了resize方法,图片依然出现变形。通过深入POI源码调试,发现宽度计算正确,但问题在于常量PX_MODIFIED的值。将PX_MODIFIED从36.56f调整为32.00f,解决了在Excel2000中图片走形的问题。不过,此解决方案可能需要针对其他Excel版本进行测试。
摘要由CSDN通过智能技术生成

最近在excel2000的版本上用POI插入图片的时候,即使调用resize方法,插入的图片还是走形了。

     patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_PNG).resize(1.0)

最近只好跟进POI的代码中debug。发现是宽度计算的对。

    public HSSFClientAnchor getPreferredSize(double scale){
        HSSFClientAnchor anchor = (HSSFClientAnchor)getAnchor();

        Dimension size = getImageDimension();
        double scaledWidth = size.getWidth() * scale;
        double scaledHeight = size.getHeight() * scale;

        float w = 0;

        //space in the leftmost cell
        w += getColumnWidthInPixels(anchor.col1)*(1 - (float)anchor.dx1/1024);
        short col2 = (short)(anchor.col1 + 1);
        int dx2 = 0;

        while(w < scaledWidth){
            w += getColumnWidthInPixels(col2++);
        }

        if(w > scaledWidth) {
            //calculate dx2, offset in the
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值