• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to Create Binary data for my Image inside My Script

Enthusiast ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

Hi Experts,

I Wish to know if possible to include the image data as binary inside my script instead just showing my image inside the script, for now i use the following :

//Script Path with Image
var scriptFile = new File($.fileName);
var scriptPath = scriptFile.parent.fsName;

var w = new Window ("dialog", "Testing");
var pics = w.add ("image", undefined, File (scriptPath+"/MyScriptName_.png"));
w.show ();

and the Result is this :

My Script Name v3.jpg

but this mean i have to distribute the Script + Image file (Png) in my case, and i think this is frustrating! and may cause errors if some one forget to copy the image within script folder (in same place), So Can i convert image into binary data and use it inside my script? and How? and thanks in Advance.

 

Best
Mohammad Hasanin
TOPICS
Scripting

Views

655

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 11, 2021 Dec 11, 2021

Hi @M.Hasanin, check out page 115 of Peter Kahrel's book on ScriptUI.

- Mark

Votes

Translate

Translate
Community Expert ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

Hi @M.Hasanin, check out page 115 of Peter Kahrel's book on ScriptUI.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

LATEST

Thanks @m1b alot

I read it and Succesfully Convert my Image to Binary,, My Modified Script is :

//Script Path with Image
var scriptFile = new File($.fileName);
var scriptPath = scriptFile.parent.fsName;

//Convert the contents of the binary file to a string
var infile = File (scriptPath+"/MyScriptName_.png");
var outfile = File (scriptPath+"/MyScriptName.txt");
infile.open ("r");
infile.encoding = "binary";
var temp = infile.read();
infile.close();
outfile.open ("w");
outfile.write (temp.toSource ());
outfile.close ();
Best
Mohammad Hasanin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines