Issues when Cropping an image

Hi I am reading in a byte [] into a image and having trouble cropping the image after inserting it into the aspose.cells.worksheet. The image being read into the stream needs to crop to the bottom 4th of the page. See code below.


Dim book As New Aspose.Cells.Workbook(xlsDocPath)

'Get the first worksheet
Dim sheet As Aspose.Cells.Worksheet = book.Worksheets(0)

Dim ansTif2() As Byte

ansTif2 = File.ReadAllBytes(“C:\ans.tif”)

Dim stream As MemoryStream = New MemoryStream()
stream.Write(ansTif2, 0, ansTif2.Length)

Dim infoImage As System.Drawing.Image = System.Drawing.Image.FromStream(stream)


'Insert a picture into a cell using a stream
'sheet.Pictures.Add(12, 1, stream, 100, 100)
sheet.Pictures.Add(20, 0, stream)

Dim pic As Aspose.Cells.Drawing.Picture
pic = sheet.Pictures(1)

pic.FormatPicture.Brightness = 0.5F
pic.FormatPicture.Contrast = 0.5
pic.IsLockAspectRatio = False
’ Set the picture size format
pic.Height = 400.0F
pic.Width = 600.0F
’ Set the picture trimming
pic.FormatPicture.TopCrop = 450.0F
pic.FormatPicture.BottomCrop = 85.0F
pic.FormatPicture.RightCrop = 40.0F
pic.FormatPicture.LeftCrop = 5.0F
'pic.Top = 536
'pic.Left = 6
book.Save(“c:\temp.xls”, SaveFormat.Excel97To2003)



Hi,


I have tested your scenario/case a bit using latest fix/version: Aspose.Cells for .NET v7.5.0.4., I used the following code minimizing the top, right cropping attributes a bit from your code segment, it works fine I think.

Sample code:

Dim book As New Aspose.Cells.Workbook()

‘Get the first worksheet
Dim sheet As Aspose.Cells.Worksheet = book.Worksheets(0)

Dim ansTif2() As Byte = Nothing

ansTif2 = File.ReadAllBytes(“e:\test\school.jpg”)

Dim stream As New MemoryStream()
stream.Write(ansTif2, 0, ansTif2.Length)

Dim infoImage As System.Drawing.Image = System.Drawing.Image.FromStream(stream)


‘Insert a picture into a cell using a stream
sheet.Pictures.Add(12, 1, stream, 100, 100)
sheet.Pictures.Add(20, 0, stream)

Dim pic As Aspose.Cells.Drawing.Picture = Nothing
pic = sheet.Pictures(0)

pic.FormatPicture.Brightness = 0.5F
pic.FormatPicture.Contrast = 0.5
pic.IsLockAspectRatio = False
’ Set the picture size format
pic.Height = 400
pic.Width = 600
’ Set the picture trimming
pic.FormatPicture.TopCrop = 4.0F
pic.FormatPicture.BottomCrop = 8.0F
pic.FormatPicture.RightCrop = 4.0F
pic.FormatPicture.LeftCrop = 5.0F
pic.Top = 536
pic.Left = 6

book.Save(“e:\test2\outimagebook1.xls”, SaveFormat.Excel97To2003)

I have attached the output file for your reference.

I am not sure what kind of cropping attributes you are looking for and what is desired result. We request you to kindly attach your template Excel file, your picture file and output file by using the code. Also, attach your expected file having your desired picture’s cropping options that you may manually create the file in MS Excel. We will check your issue soon.

Thank you.

Thanks for the quick response.

I have attached the following files:
- orginal.xls
- ans.tif
- CurrentOutputFile.xls
- FinalExpectedFile.xls

I can see towards the bottom there is an image in CurrentOutputFile, but the ans.tif image isn't present.

Please let me know if you need more information.

Current Code:

Dim book As New Aspose.Cells.Workbook(xlsDocPath)

'Get the first worksheet
Dim sheet As Aspose.Cells.Worksheet = book.Worksheets(0)

'Dim ansTif2() As Byte

'ansTif2 = File.ReadAllBytes("C:\\Users\\dsedlak\\Desktop\\Sumitomo\\Prod\\203808530_0_30904\\ans.tif")


Dim stream As MemoryStream = New MemoryStream()
stream.Write(ansTif, 0, ansTif.Length)

Dim infoImage As System.Drawing.Image = System.Drawing.Image.FromStream(stream)

'Insert a picture into a cell using a stream
'sheet.Pictures.Add(12, 1, stream, 100, 100)
sheet.Pictures.Add(32, 0, stream, 1, 1)

Dim pic As Aspose.Cells.Drawing.Picture
pic = sheet.Pictures(1)

pic.FormatPicture.Brightness = 0.5F
pic.FormatPicture.Contrast = 0.5
pic.IsLockAspectRatio = False
' Set the picture size format
pic.Height = 200.0F
pic.Width = 300.0F
' Set the picture trimming
pic.FormatPicture.TopCrop = 450.0F
pic.FormatPicture.BottomCrop = 85.0F
pic.FormatPicture.RightCrop = 40.0F
pic.FormatPicture.LeftCrop = 5.0F
'pic.Top = 536
'pic.Left = 6

book.Save("c:\temp.xls", SaveFormat.Excel97To2003)

Hi,


Thanks for providing us sample files.

After an initial test, I am able to find the issue as you have mentioned. I have noticed the issue, the cropping attributes are not working as expected. Also, if I read the cropping options these attributes are always “0” for your expected file (I loaded the file and then read the attributes).
e.g

Sample code:
//…
Console.WriteLine(pic.FormatPicture.TopCrop);
Console.WriteLine(pic.FormatPicture.BottomCrop);
Console.WriteLine(pic.FormatPicture.RightCrop);
Console.WriteLine(pic.FormatPicture.LeftCrop);

I have logged a ticket with an id “CELLSNET-41809” for your issue. We will look into it to figure it out soon.

Thank you.

Thanks again for the quick response.


We are currently evaluating Aspose.Cell .Net. for use with picture inserting and tiff conversion

Do you know what the estimated time is to resolve this issue?

If this can be resolved within a timely manner I believe we will be purchasing your product.

Dan

Hi,


Please spare us some time as we need to evaluate your issue thoroughly first. Our concerned developer will look into it soon. Once we analyze the issue, we can either fix it (if the issue is with our product and not very complex) very soon or we can share an eta with you if it takes more time.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells.

The value of crop should be a ratio of the image’s width or
height.

Please see the following code.

C#
pic.FormatPicture.TopCrop = 450.0F/
pic.Height;
pic.FormatPicture.BottomCrop = 85.0F/
pic.Height;
pic.FormatPicture.RightCrop = 40.0F/
pic.Width;
pic.FormatPicture.LeftCrop = 5.0F / pic.Width;