I have logged the results and findings against your issue “CELLSNET-45704” into our database. Our concerned developer from product team will evaluate your issue further soon.
Please try executing the following lines of code on Azure and check that the file ‘Result.emf’ is correct:
e.g Sample code:
RectangleF dstRectF = new RectangleF(0, 0, 673f, 360f);
Bitmap dummyBitmap = new Bitmap(1, 1);
Graphics dummyGfx = Graphics.FromImage(dummyBitmap);
hdc = dummyGfx.GetHdc();
MemoryStream msOut = new MemoryStream();
Metafile metafile = new Metafile(msOut, hdc, dstRectF, MetafileFrameUnit.Pixel, EmfType.EmfPlusDual);
Graphics g = Graphics.FromImage(metafile);
byte[] Data = SaveImage(path +"\\image1.emf");
Stream Ms = new MemoryStream(Data);
Image Ima = Image.FromStream(Ms,true);
g.DrawImage(Ima, dstRectF);
g.Dispose();
msOut.Seek(0, SeekOrigin.Begin);
Image img = Image.FromStream(msOut);
img.Save(path + "\\Result.emf", ImageFormat.Emf); //or img.Save(path + "\\Result.png", ImageFormat.Png);
Note: ‘image1.emf’ is the picture in Excel.
If no error is occurred. Please provide two files that you generated in debug run and network job(4k\151bytes).
We will check if we could provide you the exact lines of code written in “SaveImage” custom method, so you may compile the code segment seamlessly. But, the underlying method only gets the image file into byte array, so you may easily replace the following line with your own code to read the contents of the image file into array of bytes by yourself:
That might be the reason it fails for image/shape rendering. I have logged your log contents and findings against your issue “CELLSNET-45704” into our database. Our concerned developer from product team will evaluate it further and we will get back to you soon.
Well, Metafile(e.g. emf, wmf) images are widely used in Microsoft Excel. A solution is that we can add an option to let you set to draw metafile to bitmap, but this may cause the output image a little blurred in the output PDF.
Could you try to check whether the following code works on your Azure web job:
e.g Sample code:
using (Image srcImage = Image.FromFile("image1.emf"))
{
using (Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height))
{
destImage.SetResolution(srcImage.HorizontalResolution, srcImage.VerticalResolution);
using (Graphics g = Graphics.FromImage(destImage))
{
g.DrawImage(srcImage, new RectangleF(0, 0, srcImage.Width, srcImage.Height));
}
using (MemoryStream ms = new MemoryStream())
{
destImage.Save(ms, ImageFormat.Png);
//test save to file
using (FileStream fs = new FileStream("imageOut.png", FileMode.Create))
{
byte[] imageData = ms.ToArray();
fs.Write(imageData, 0, imageData.Length);
}
}
}
}
if the code works and you accept the solution, we will add an option for you.
Please note, “image1.emf” is extracted from your Excel file. image1.zip (21.1 KB)
We are sorry that this does not work in Azure. As you are also approaching Microsoft to sort it out (if possible). Your thread (logged earlier as "CELLSNET-45704 ") is till open and we will check and evaluate further if we have other options to cope with it.
Once we have any new information, we will update you here.
I think you may try to remove the image(s) in the file (in code) before rendering, see the sample line of code:
e.g Sample code:
… worksheet.Pictures.RemoveAt(index);
Alternatively, could you try using filtering option while loading your file in Azure. See the sample code segment for your reference:
e.g Sample code:
var filePath = "e:\\test2\\Book1.xlsx";
//Load everything except shapes.
var loadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.Shape);
var asposeOptions = new Aspose.Cells.LoadOptions
{
MemorySetting = MemorySetting.MemoryPreference,
LoadFilter = loadFilter
};
var workbook = new Workbook(filePath, asposeOptions);
Good to know that your issue is sorted out now. Feel free to write us back if you have further comments or questions, we will be happy to assist you soon.