Import JPG on Fly & Show In Navision

SavatageSavatage Member Posts: 7,142
edited 2013-03-11 in NAV Tips & Tricks
It's been discussed how to save your Item pictures on an outside drive and show them in Nav on the fly as BMP. This way you Database doesn't grow out of control when you have to import 10000 pics into BLOB fields.

You can also have JPG pics on an outside drive and show them in Nav.

To Test use Form 346 item Picture

OnAfterGetRecord add

SETRANGE("No.");
IF EXISTS ('P:\jpg\'+"No."+'.jpg')
 THEN BEGIN
  ConvertPic:= SHELL('i:\navision attain\jpg2bmp.exe -outfile c:\temp.bmp -color 256 -bmp -scale 1/1 p:\jpg\'+"No."+'.jpg');
  Picture.IMPORT('c:\temp.bmp',FALSE);
END
 ELSE BEGIN
  CLEAR(Picture);
END;

ConvertPic Type Integer

i:\navision attain\jpg2bmp.exe //is the drive & directory of the EXE that I used, which you can find here: http://www.mibuso.com/dlinfo.asp?FileID=70

'P:\jpg\'+"No."+'.jpg' //is the directory we keep our JPG pics (P:\jpg) Also the pictures are named as it's Item Number hence the "No."
But you could easily change it to UPC or Vendor Item No if that's how you name your pics.

I have set the SCALE to 1/1 but the other choices are
half = 1/2
quarter = 1/4
eigth = 1/8
this will reduce the pic size.

Most pc's are fast today and the EXE file flashes it's little Dos box for an instance - I forgot the command that makes that invisible running behind the scenes. Perhaps stuffing it into a BAT file. anyway...

Comments

  • TomasTomas Member Posts: 420
    I get error message when clicking Item->Picture:

    Microsoft Business Solutions-Navision
    The file name "C:\jpg\jpg2bmp\jpg2bmp.exe -outfile c:\temp.bmp -color 256 -bmp -scale 1/1 C:\jpg\1000.jpg" contains a character that may not be used.

    Please check the file name. You can find additional information on file names in the documentation for your operating system.

    OK

    Any ideas, suggestions?

    EDIT: if i execute same command from cmd line, it succeeds.
  • krikikriki Member, Moderator Posts: 9,112
    Savatage wrote:
    I forgot the command that makes that invisible running behind the scenes. Perhaps stuffing it into a BAT file. anyway...
    Check this : http://www.mibuso.com/forum/viewtopic.php?t=12417 and use WindowStyle=0.

    @Tomas : probably you need to put some parameters between double quotes.

    [Topic moved from Navision Attain forum to Navision Tips & Tricks forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • TomasTomas Member Posts: 420
    Path := 'C:\jpg\';        // might be defined in custom setup form and pointing to shared drive
    WindowsStyle := 0;        // do not show cmd window
    WaitForCommand := TRUE;   // wait for command to finish
    
    SETRANGE("No.");     
    
    IF EXISTS (Path+"No."+'.jpg') THEN 
    BEGIN
        CREATE(WShell);
        Cmd := Path+'jpg2bmp\jpg2bmp.exe -outfile '+Path+'temp.bmp -color 256 -bmp '+Path+"No."+'.jpg';
        WShell.Run(Cmd,WindowsStyle,WaitForCommand);
        CLEAR(WShell);
        Picture.IMPORT(Path+'temp.bmp',FALSE);
    END 
    ELSE BEGIN
      CLEAR(Picture); 
    END;
    

    The only issue left is that if we put images (and jpg2bmp.exe) on a shared drive, everytime we'll display image, we'll have to cofirm that we trust that program.

    Otherwise, thanks Savatage and kriki for a wonderful tip! \:D/
  • SavatageSavatage Member Posts: 7,142
    I don't get that issue - are you running Vista?
  • TomasTomas Member Posts: 420
    Savatage wrote:
    I don't get that issue - are you running Vista?

    Hmnz,

    No. I am running on Windows XP. I have copied exe file to other computer and mapped a new drive for that folder. Each time I want to open Item Picture form I get Open File - Security Warning:
    The publisher could not be verified. Are you sure you want to run this software? 
    
    Name: jpg2bmp.exe
    Publisher: Unknow Publisher
    Type: Application
    From: H:\jpg\jpg2bmp
    
  • SavatageSavatage Member Posts: 7,142
    From: H:\jpg\jpg2bmp

    Perhaps if you save the jpg2bmp.exe from your client folder or a drive on your PC instead of having the program on a network drive - it will not think it's an outside program every time.
  • TomasTomas Member Posts: 420
    Savatage wrote:
    From: H:\jpg\jpg2bmp

    Perhaps if you save the jpg2bmp.exe from your client folder or a drive on your PC instead of having the program on a network drive - it will not think it's an outside program every time.

    Yes, but this means, that you need to copy same program to all user machines, instead of placing it somewhere in the network in one place. :?
  • SavatageSavatage Member Posts: 7,142
    you have to pick which is the lesser of two evils for your situation.

    If you have 10 machines then it's not a problem
    you have 100 then ouch!
  • garakgarak Member Posts: 3,263
    Yes, but this means, that you need to copy same program to all user machines, instead of placing it somewhere in the network in one place

    I'ved solved this problem, it was an other progamm (DLL), as following:

    I've stored my dll (which i needed on ever client pc) into a BLOB in a special table. When the user want's to run the Navision Object which need my DLL i checked before if this DLL is registerd (for example in table Automations) if it is not reg. i extract it from the BLOB to an defined folder and regist. it with regsrv / regasm. So the users can use my DLL /or others on every PC. The admins doesn't need to install this when they setup a new PC.

    the same principle u can use for this problem .....

    Regards
    René
    Do you make it right, it works too!
  • garakgarak Member Posts: 3,263
    Wow, Luc has the same idea .....

    An other idea is, when you not will map the network drives, that u use the UNC path. For using UNC here in the forum are some examples.
    Do you make it right, it works too!
  • imurphyimurphy Member Posts: 308
    I suspect this will stop working with vista and it will certainly not work on machines where the user is not an admin.

    As an admin you can install a dll onto every machine in the network using the psexec tool from MS (www.sysinternals.com will take you to the correct page).

    Two commands will do the trick and you can probably do it with one.

    psexec \\* copy \\fromserver\fromshare\fromdll.dll c:\windows\system32\todll.dll
    psexec \\* regsvr32 c:\windows\system32\todll.dll

    psexec \\* executes the command on every machine in the network.

    Ian
  • Prajeesh_NairPrajeesh_Nair Member Posts: 70
    hiii pros.. :shock:
    I am new to navision but i tried the code given by Thomas. but when i compiled I got some problem ](*,)

    1. Unknown Variable Wshell :-k
    I can define this in Global but what is the data type is it a function?
    2. Cmd unknown variable
    And I have some more doubts where is this Windows Style: = 0; defined is it a property?
    [-o<
  • SavatageSavatage Member Posts: 7,142
    hiii pros.. :shock:
    I am new to navision but i tried the code given by Thomas. but when i compiled I got some problem ](*,)

    1. Unknown Variable Wshell :-k
    I can define this in Global but what is the data type is it a function?
    2. Cmd unknown variable
    And I have some more doubts where is this Windows Style: = 0; defined is it a property?
    [-o<

    Wshell->Datatype=Automation->Subtype=Windows Script Host Object Model->WshShell
    I assume CMD is type integer
  • Nico_DekkerNico_Dekker Member Posts: 7
    Hi,

    We're using the code below in form 30 (Item Card), and that works great.
    Path := 'C:\jpg\';        // might be defined in custom setup form and pointing to shared drive
    WindowsStyle := 0;        // do not show cmd window
    WaitForCommand := TRUE;   // wait for command to finish
    
    SETRANGE("No.");     
    
    IF EXISTS (Path+"No."+'.jpg') THEN 
    BEGIN
        CREATE(WShell);
        Cmd := Path+'jpg2bmp\jpg2bmp.exe -outfile '+Path+'temp.bmp -color 256 -bmp '+Path+"No."+'.jpg';
        WShell.Run(Cmd,WindowsStyle,WaitForCommand);
        CLEAR(WShell);
        Picture.IMPORT(Path+'temp.bmp',FALSE);
    END 
    ELSE BEGIN
      CLEAR(Picture); 
    END;
    

    We only encounter one strange problem. If a user keeps pressing the navigate buttons (Back or Forward) in the toolbar, a Navision messagebox pops up stating "Do you want to change the name of the record? (Yes - No)". This occurs just before a record that contains a picture is displayed. The result is that the previous item now shows the image which is wrong.
    So what might be the problem regarding the messagebox and showing the image one record to early?

    Hope someone has an answer.

    Nico Dekker
    The Netherlands
  • SavatageSavatage Member Posts: 7,142
    So you showing the pic right on the item card & not using Item Picture form 346.

    Which trigger to you have the code on? if I get a second I'll try your code and see what my results are.
  • DevendraSharmaDevendraSharma Member Posts: 23
    Tomas wrote:
    Path := 'C:\jpg\';        // might be defined in custom setup form and pointing to shared drive
    WindowsStyle := 0;        // do not show cmd window
    WaitForCommand := TRUE;   // wait for command to finish
    
    SETRANGE("No.");     
    
    IF EXISTS (Path+"No."+'.jpg') THEN 
    BEGIN
        CREATE(WShell);
        Cmd := Path+'jpg2bmp\jpg2bmp.exe -outfile '+Path+'temp.bmp -color 256 -bmp '+Path+"No."+'.jpg';
        WShell.Run(Cmd,WindowsStyle,WaitForCommand);
        CLEAR(WShell);
        Picture.IMPORT(Path+'temp.bmp',FALSE);
    END 
    ELSE BEGIN
      CLEAR(Picture); 
    END;
    

    The only issue left is that if we put images (and jpg2bmp.exe) on a shared drive, everytime we'll display image, we'll have to cofirm that we trust that program.

    Otherwise, thanks Savatage and kriki for a wonderful tip! \:D/



    When i run this function then i found ole error

    Microsoft Dynamics NAV
    This message is for C/AL programmers:

    An exception was raised in method Run. The OLE control or Automation server has returned error (HRESULT) -2147352567.
    The component did not provide the exception description.

    OK
    now what i do

    Thank's !!!
    Devendra
  • SavatageSavatage Member Posts: 7,142
    Wshell->Datatype=Automation->Subtype = Windows Script Host Object Model->WshShell
    Cmd = Integer
    WindowsStyle = Integer
    WaitForCommand = Boolean

    What do you have these declared as?
  • rajeshasarrajeshasar Member Posts: 7
    I declared

    Cmd = Text 250 and it works :)

    Further I did generated temp.bmp in user level temp folder to avoid multi user conflict (Here the jpg name was based on "Design No." and there were multiple item with same design no. )

    - Rajesh Asar
  • rdebathrdebath Member Posts: 383
    When I did this I used IrfanView, it can convert and resize a lot of different image formats from the command line.
  • ty0699ty0699 Member Posts: 2
    When I run this function I also get following error message.
    An exception was raised in method Run. The OLE control or Automation Server has returned error (HERSULT) -2147352567.

    Can anyone please help.
  • SavatageSavatage Member Posts: 7,142
    rajeshasar wrote:
    I declared

    Cmd = Text 250 and it works :)

    Further I did generated temp.bmp in user level temp folder to avoid multi user conflict (Here the jpg name was based on "Design No." and there were multiple item with same design no. )

    - Rajesh Asar
  • Suman_MaharjanSuman_Maharjan Member Posts: 1
    Dear all,

    I have tried this technique to import the jpg file but the problem is the photo is not converted. i have taken "cmd" variable as text 250 because whenever i choose the datatype of this variable as integer, the error appears for the datatype "integer := text". the photo i have chosen is not converted to bmp. please suggest me where am i wrong??

    Path := 'D:\';
    WindowsStyle := 0;
    WaitForCommand := TRUE;

    SETRANGE("No.");
    IF EXISTS (Path+"No."+'.jpg') THEN
    BEGIN
    CREATE(Wshell);

    cmd := Path+'jpg2bmp\jpg2bmp.exe -outfile'+Path+"No."+'.bmp -color 256 -bmp'+Path+ "No."+'.jpg';

    Wshell.Run(cmd,WindowsStyle,WaitForCommand);
    CLEAR(Wshell);
    Photo.IMPORT(Path+"No."+'.bmp',FALSE);
    END
    ELSE BEGIN
    CLEAR(Photo);
    END;
  • SavatageSavatage Member Posts: 7,142
    is you executable in D:\jpg2bmp\jpg2bmp.exe?
  • rdebathrdebath Member Posts: 383
    cmd := Path+'jpg2bmp\jpg2bmp.exe -outfile'+Path+"No."+'.bmp -color 256 -bmp'+Path+ "No."+'.jpg';
    :bug:

    Looks like you're missing the spaces, you do have to be precise for this to work.

    You can use a MESSAGE to popup the cmd that's being used and copy&paste that into a cmd shell to check.
Sign In or Register to comment.