Jump to content

Open TIFF-Files with 'invalid'-Fileextension


Recommended Posts

Hi,

is there a possibility to open image-files in TIFF format, which have "invalid"-fileextensions?

All my files are double sided scans with fileextension file.1 (first side) and file.2 (second page). It is impossible to copy and/or rename these files.

How can I make Paint.Net to accept *.1 and *.2 files as valid image-files?

 

Thanks in advance & best wishes,

Heiko

 

Link to post
Share on other sites

The easiest way is to rename them & give them the correct file extension. Why do you state this is "impossible"?

Link to post
Share on other sites

In my case it is 'impossible'. These files are opened from a read-only device and it is strictly forbidden to copy/save any of this data on the local storage. This is why I stated 'impossible'.

What I didn't know & I don't understand is, why Paint.Net refuses to open the files just because of an invalid file-extension. Even the Windows Imageviewer doesn't care about the file-extension and opens any file.

Never the less it would be great if anyone could point out a solution besides renaming the file. Is it somehow possible to tell Paint.Net that .1 / .2 is a know image type?

Edited by pworm
typo
Link to post
Share on other sites

Paint.NET looks at the extension to determine the file type. It does not inspect the file itself in order to determine the file type.

 

Windows Image Viewer is based on WIC (Windows Imaging Component) which does inspect the file itself in order to determine which codec to use for decoding the image.

 

In order to open with Paint.NET, you will need to rename the file, or write your own FileType plugin that does what you need. There is no other solution.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to post
Share on other sites

Ok, thanks for your replys. Actually I am not a coder except some very basic Java knowledge. But I managed it to create a functional Filetype plugin. I have no idea, if it is good coding style but at least it is working for me and I'd like to share this here - just in case someone is having a similar problem.

 

My code is based on a project template created by toe_head2001 - thanks man, that helped a lot:

 

using PaintDotNet;
using System.IO;
using System.Drawing;

namespace RoHoFileTypePlugin2
{
    public sealed class RoHoFileTypePlugin2Factory : IFileTypeFactory
    {
        public FileType[] GetFileTypeInstances()
        {
            return new[] { new RoHoFileTypePlugin2Plugin() };
        }
    }

    [PluginSupportInfo(typeof(PluginSupportInfo))]
    internal class RoHoFileTypePlugin2Plugin : FileType
    {
        // Constructs a ExamplePropertyBasedFileType instance
        internal RoHoFileTypePlugin2Plugin()
            : base(
                "MyFileType",
                new FileTypeOptions
                {
                    LoadExtensions = new string[] { ".1", ".2" },
                })
        {
        }

        /// <summary>
        /// Creates a document from a stream
        /// </summary>
        protected override Document OnLoad(Stream input)
        {
            Image image = Image.FromStream(input, true);
            return Document.FromImage(image);
        }
    }
}

 

Edited by pworm
  • Like 1
  • You're a Smart Cookie! 1
Link to post
Share on other sites

Great solution.

 

Who cares if it is bad code?? It works for you and that is the important bit :mrgreen:

  • Like 2
  • Upvote 1
Link to post
Share on other sites
On 12/21/2020 at 1:19 PM, Ego Eram Reputo said:

Who cares if it is bad code?? It works for you and that is the important bit :mrgreen:

 

This is really important. A lot of people get hung up on their code being {insert negative words here}. Don't forget to answer: does it work for its intended audience? Does it need improvement (yet)? 

 

There is a LOT of code out there in the wild that is kinda janky looking but it works and solves real problems for real people in the real world. Case closed :) I don't care if my microwave has weird looking code because it works and doesn't give me any trouble, and I appreciate that.

  • Upvote 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

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.

×
×
  • Create New...