-
Notifications
You must be signed in to change notification settings - Fork 558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New ImagePart is created as .bin instead of real extension #1305
Comments
Will deleting the following lines be enough to prevent this behaviour? I am imitating this #1292 fix, that @mikeebowen made. He replaced .xml with .bin. Instead, I delete the same lines. From:
From:
From:
|
I'm having the same issue within the Word document when embedding png files. @Asbjoedt Do you have a working fix for the issue? |
@faerbersteve I think deleting the above lines are maybe only a part of the way. I found the following methods in the SDK. I don't have a clear overview of how to proceed from here though.
|
Hi @twsouthwick, @tomjebo I have written a fix for this, you can see here: https://github.com/dotnet/Open-XML-SDK/compare/main...Asbjoedt:Open-XML-SDK:ImagePartFix?expand=1 I am not entirely sure the fix works, because I have problems building Open XML SDK to test the new code (approx. 200 namespace references are missing). Maybe you can help me out somehow. The fix does two things:
|
This file is where the
|
* fix boolean logic for file extension when adding OpenXmlPart. Fixes #1305 * add tests for correct file extension when adding OpenXmlPart
Great! thx. |
* fix boolean logic for file extension when adding OpenXmlPart. Fixes dotnet#1305 * add tests for correct file extension when adding OpenXmlPart
…t file extension when adding ImagePart. Fixes dotnet#1305
* Fix boolean logic for finding file extensions * add test for correct file extension when adding ImagePart. Fixes #1305
Confirmed fix. |
@mikeebowen Not fixed for ImagePart generated by this way in version 2.20:
|
@Wenfengcheng , What is the issue you're seeing? Does it use the wrong extension? Does it throw an error? Something else? |
@mikeebowen yeah, the extension is wrong which is .bin file, not the origin image extension. |
+1 can confirm the same issue of a var codes = ImageCodecInfo.GetImageDecoders();
var mimeType = codes.First(c => c.FormatID == image.RawFormat.Guid).MimeType;
var imagePart = mainPart.AddImagePart(mimeType); // image/jpeg
using var stream = new MemoryStream();
image.Save(stream, image.RawFormat);
stream.Position = 0;
imagePart.FeedData(stream); |
@mikeebowen can you take a look to see what's different here? |
We'll track this in the new issue as it looks subtly different |
Describe the bug
I have asked the question on Stackoverflow:
https://stackoverflow.com/questions/75100804/embedding-image-as-new-imagepart-creates-a-bin-file-using-open-xml-sdk
I don't expect to get any answer there, and I am also increasingly curious whether, this is an implementation error but an issue in the SDK.
Issue is, I create new embedded image in Excel and it is saved to
/xl/media/image.[WhatEverExtensionItIs]
If I create a new ImagePart with the SDK and feed it data like this:
Then the file will be saved as
/xl/media/image.bin
.This behaviour it should not do. It should write the extension as .tiff, since this is the
ImagePartType
, that I specify. Or secondly it should read the stream and identify it as .tiff through i.e. a magic number.If you unzip the package and change the image extension to real extension, then the image will open perfectly and I have used a TIFF validator to confirm the image is well-formed.
What do you think of this? Am I doing anything wrong in my implementation, or can we change the SDK to write real extension like Excel does?
Screenshots
If applicable, add screenshots to help explain your problem.
To Reproduce
Steps to reproduce the behavior:
Observed behavior
ImagePart creates a new image with .bin extension
Expected behavior
ImagePart should create a new image with extension based on ImagePartType.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: