Skip to content

Commit

Permalink
修复linux下无法导出jpg格式图片bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
zqlovejyc committed Sep 2, 2021
1 parent 16493a1 commit fc2bce1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ZqUtils.Core/Helpers/ExcelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -961,8 +962,15 @@ public static void BuildExcelHeader(ExcelHeaderCell prevCell, ExcelHeaderCell pa
var imageValue = sheet.Cells[row, col].Value;
if (imageValue != null && imageValue is byte[] imgeBytes)
{
//获取图片
using var image = Image.FromStream(new MemoryStream(imgeBytes));
//加载图片
using var originImage = Image.FromStream(new MemoryStream(imgeBytes));

//转换图片格式为png,修复jpg在linux下无法导出的问题
using var pngStream = new MemoryStream();
originImage.Save(pngStream, ImageFormat.Png);

//重新加载图片
using var image = Image.FromStream(pngStream);

//设置行高
sheet.Row(row).Height = image.Height;
Expand Down

0 comments on commit fc2bce1

Please sign in to comment.