Free Support Forum -

How do I resize a picture added using a stream?

I am attempting to add a picture to a cell using a stream but cannot seem to resize it correctly. When using public int Add(int,int,Stream,int,int); the ratios seem to be ignored andit always inserts a picture of width and height 0.. The following code creates a picture of the corerect height but a width of 'zero'. Inserting the same picture directly from a file correctly creates the picture with correct sizing

MemoryStream imgStrm = new MemoryStream();

imgStrm.Write(imgBytes, 0, imgBytes.Length);



Image infoImage = Image.FromStream(imgStrm);

int picIdx = excelDoc.Worksheets[0].Pictures.Add(rowNo, colCnt, imgStrm, 100, 100);
excelDoc.Worksheets[0].Pictures[picIdx].Top = 1;
excelDoc.Worksheets[0].Pictures[picIdx].Left = 0;
sheetCells.SetRowHeight(rowNo, infoImage.Height+2);

}catch (Exception)




Which version of Aspose.Cells are you using? I don't find the problem. Following is my sample code:

Workbook excel = new Workbook();

FileStream fs = File.OpenRead("d:\\logo.jpg");

byte[] data = new Byte[fs.Length];
fs.Read(data, 0, data.Length);

MemoryStream stream = new MemoryStream();
stream.Write(data, 0, data.Length);

Image infoImage = Image.FromStream(stream);
excel.Worksheets[0].Pictures.Add(2, 2, stream, 100, 100);
excel.Worksheets[0].Pictures[0].Top = 1;
excel.Worksheets[0].Pictures[0].Left = 0;


What's the format of your image file? Is it a gif, jpg or other format image file?

Sorry for the lack of information. I am using version and the image is a png which is held in a database. I will try your example to see if it works as exepected


The problem appears to be with the originating images as they have zero resolution in their properties. IE and Microsoft picture manager seem to cater for this somehow, presumably autocorrecting as necessary. I dont suppose you have plans to do something similar? I can send you a sample file if you like.


You can attach your image file here or send it to .

If it's not very difficult to solve it, I will try to make it in Aspose.Cells. Otherwise, it's better to change your image file to a "normal" image file. Thanks.

I have emailed some images


Please try this version.

Perfect! Thanks for your quick response