skip to Main Content

I am having trouble viewing files with .png encoding without the .png file extension in Visual Studio Code. It will only show the warning "The file is not displayed because it is either binary or uses an unsupported text encoding.". Trying to select an editor only provides the options "text" or "hex".

So, is it possible to change the file association of a given file extension to inform VS Code to render that file as a .png, or other image type?

I have tried adding the lines "files.associations": { "*.otherfiletype": "png" } to my settings.json, but this has no effect.

2

Answers


  1. You can use the workbench.editorAssociations setting. Ex. in settings.json:

    "workbench.editorAssociations": {
        "*.jpg2": "imagePreview.previewEditor",
    },
    

    It will still give a warning that

    The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding.

    But the change will allow you to click the "Open Anyway" button and be presented with the option to open it with the "Image Preview" (builtin) custom editor.

    Login or Signup to reply.
  2. Visual Studio Code (VS Code) is primarily designed as a text editor and does not inherently support viewing image files like .png files directly within the editor. The "files.associations" configuration in VS Code settings is meant for associating file extensions with specific programming languages, not for rendering images.

    However, you can achieve your goal using a VS Code extension called "Image Preview" which allows you to preview image files within the editor.

    Find the "Image Preview" extension by Kamesh Kotwani and click the "Install" button.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search