macneacail

Trouble loading BMP files

Recommended Posts

Paint.net 4.2 will not open bmp files created using Microsoft Drawing Routines.  paint.NET has been opening these files since 2012

Application version: paint.net 4.2

PaintDotNet.Imaging.UnknownImageFormatException (0x88982F07): D:\src\pdn\src\SystemLayer.Native\Imaging\WICImagingFactory.cpp (892) : hr = spDecoder->Initialize( spStream, static_cast<WICDecodeOptions>(metadataOptions));
   at PaintDotNet.Interop.InteropErrorInfo.ThrowIfError() in D:\src\pdn\src\Base\Interop\InteropErrorInfo.cs:line 98
   at PaintDotNet.SystemLayer.Native.x64.NativeUtilities.ThrowOnErrorImpl(Int32 hr, SByte* szHr, IUnknown* pFxErrorInfo)
   at PaintDotNet.SystemLayer.Native.x64.Imaging.WICImagingFactory.CreateDecoderFromStream(Stream stream, BitmapDecodeOptions metadataOptions, Nullable`1 containerFormat, Nullable`1 preferredVendor)
   at PaintDotNet.Data.WicFileTypeHelpers.Load(Stream input, Nullable`1 forcedContainerFormat, Nullable`1 preferredVendor, MetadataTranscoder metadataTranscoder) in D:\src\pdn\src\PaintDotNet\Data\WicFileTypeHelpers.cs:line 61
   at PaintDotNet.Data.BmpFileType.OnLoad(Stream input) in D:\src\pdn\src\PaintDotNet\Data\BmpFileType.cs:line 93
   at PaintDotNet.FileType.Load(Stream input) in D:\src\pdn\src\Data\FileType.cs:line 482
   at PaintDotNet.Functional.Func.Eval[T1,TRet](Func`2 f, T1 arg1) in D:\src\pdn\src\Base\Functional\Func.cs:line 158

Share this post


Link to post
Share on other sites
2 hours ago, macneacail said:

Paint.net 4.2 will not open bmp files created using Microsoft Drawing Routines.

 

Please post a sample of one of these images.  Thanks!

 

EDIT:

 

Since you say "Drawing Routines", I'm going to hazard a guess that the files you're talking about are actually WMF files and not BMP files.  If you take a WMF file and rename it to BMP, Windows Paint (and Microsoft Word) will still open it just fine.  Paint.NET can't do that.

 

However, Paint.NET has a WMF filetype plugin that can load WMF files.  You can find it here: https://forums.getpaint.net/topic/17950-wmf-windows-metafile-file-type-plugin-v131/ But, before attempting to open the file, if it has the extension BMP you'll need to change it to WMF.

 

Share this post


Link to post
Share on other sites

Thank you for the response. 

 

Each file is about 5 MB so it will not upload. 

 

Bitmap newBmp = new Bitmap(XL, Y, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

 

creates the file 

 

I wonder why does paint.net 4.1.6 open the files and paint.net has done so since I started using it in about 2012 

John

Share this post


Link to post
Share on other sites
5 minutes ago, macneacail said:

Bitmap newBmp = new Bitmap(XL, Y, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 

 

When you save the file to disk, you need to specify the format. i.e.

newBmp.Save(@"C:\image.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

If you just do this, it will save in the PNG format (regardless of the file extension)

newBmp.Save(@"C:\image.bmp"); // Saves in the PNG format

 

Share this post


Link to post
Share on other sites
1 hour ago, macneacail said:

I wonder why does paint.net 4.1.6 open the files and paint.net has done so since I started using it in about 2012 

 

Maybe read about it? A ton has changed under the hood. https://blog.getpaint.net/2019/07/13/paint-net-4-2-is-now-available/

 

And @toe_head2001 is right. The bug is in your code and file naming, not in Paint.NET.

Share this post


Link to post
Share on other sites
4 hours ago, Rick Brewster said:

 

Maybe read about it? A ton has changed under the hood. https://blog.getpaint.net/2019/07/13/paint-net-4-2-is-now-available/

 

And @toe_head2001 is right. The bug is in your code and file naming, not in Paint.NET.

Dear Rick:

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

using (var inFile = File.OpenRead(NameofBitMap))
            {
                var decoder = BitmapDecoder.Create(inFile, BitmapCreateOptions.None, BitmapCacheOption.None);
                var encoder = new PngBitmapEncoder();

                var frame = decoder.Frames[0];
                encoder.Frames.Add(frame);

                using (var outFile = File.OpenWrite(NameofBitMap + ".png"))
                {
                    encoder.Save(outFile);
                }
            }

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

René Slijkhuis provides a simple workaround for the moment -- 

I prefer to think of bugs as unused features

I read the blog content -- interesting 

Perhaps instead of breaking BMP images created using GDI that is still legal with the perversion that bmp is really PNG in some cases - maintaining the option or putting up a more descriptive error might have been useful. Renaming BMP to PNG worked. 

But rule number 101 from Computer Science 100 in 1978 - do not criticize other people's code, I always find is useful, although often ignored. 

As the great Jerry Pournelle once said "bend the punch cards - enjoy the day"

RIP JP you are missed. 

Great program by the way. 

 

John

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.