Results 1 to 15 of 15

Thread: [RESOLVED] Image path location

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] Image path location

    I used Microsoft Access 2003, Field name "Gambar" contains image path location like this "C:\PF\GUI\ancaman padi\PENYAKIT PADI\Hawar Seludang.jpg" . When I create setup installation, there have default path location in "C:\PF" . If the user change the default location, the program will install the program to the user specific location and my program which used the image path location cannot view the image because the program install the wrong location. How I can make the image available to view any path of the location

  2. #2

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Image path location

    Yes I know it, but I have to extract the files from database to the hardisk.. I have many image files if I store in the database and take time to extract the files from database. So I just used the field name and its path location to browse the files, the files already extract during installation to the target machine, I used PWD to extract the files.

    It is posible to used app.path\ancaman padi\PENYAKIT PADI\Hawar Seludang.jpg" in the field name "Gambar" in the microsoft access?

  4. #4
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Image path location

    Why not have your application create a new directory for storing images upon installation? Or the first time the application is run, or something.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Image path location

    Quote Originally Posted by MaximilianMayrhofer
    Why not have your application create a new directory for storing images upon installation? Or the first time the application is run, or something.
    I have include all the image in this folder C:\PF\GUI\ancaman padi\PENYAKIT PADI\Hawar Seludang.jpg" . So All the installation will put this image file in this directory
    Code:
    C:\PF\GUI\ancaman padi\PENYAKIT PADI
    . It is a default. It it ok.

    But What happend when the user change the directory during installation?Of couse the image cannot display because the path location has change.So I found that my program is dependent on image path location in order the user to view the image so how to make the program and the image can be view in whatever location user install my program. Can I use App.path?

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Image path location

    We store our image paths in a table in the database

    two fields - Configuration Item and Configuration data

    For example - the .\ means to substitute APP.PATH

    Image_Employment
    .\PHOTO

    This next one is a hardwired path

    ImageProcess_Master_AdmDuesCards
    F:\AdmDuesCards

    This next one tells the app to use a STORED PROCEDURE to get the image from the DB

    Image_Student
    ~GetStuPhoto_P

    It's easy to create a method that allows you to support different options.

    But the key to all this is to have the "path" stored in the DB itself somehow.

    [edit] in case this was not clear - this is the "image path" - not the image name. If the image name needs to be stored it should be stored without a path - in a separate table [/edit]
    Last edited by szlamany; Feb 11th, 2008 at 08:47 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Image path location

    Quote Originally Posted by matrik02
    ...but I have to extract the files from database to the hardisk...
    Not necessary.
    Few months ago there was thread started by szlamany so try searching through threads he started and you will find a solution.
    We could not post all the code publicly because of a copyrights but it's easy enough to implement - everything you'll need (including links to third party) is in that thread.

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Image path location

    As RhinoBull said it's easy to accomplish.

    Link is in my signature - LOADING PICTURES FROM DB

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Image path location

    I still not clear with you post number #6, you create two field name. What is .\PHOTO ? It is a folder name? If I have image path store in the field "Gambar" like C:\PF\GUI\ancaman padi\PENYAKIT PADI\Hawar Seludang.jpg, So What should I insert in the field name I had created ?


    Code:
    Image_Employment 
    .\PHOTO
    
    This next one is a hardwired path
    
    ImageProcess_Master_AdmDuesCards
    F:\AdmDuesCards
    
    This next one tells the app to use a STORED PROCEDURE to get the image from the DB
    
    Image_Student
    ~GetStuPhoto_P

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Image path location

    Are all your images in a single folder?

    How many different images are we talking about here?

    GAMBAR is a field in what table? How many other columns in that table? Can you give us the table layout please?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Image path location

    Code:
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim arBytes() As Byte
    rs.Open "Exec " & Mid(s1, 2) & " '" & s3 & "'", gCn, adOpenForwardOnly, adLockReadOnly, adCmdText
    If rs.EOF Then
        rs.Close
        Set rs = Nothing
    End If
    arBytes() = rs(0).GetChunk(rs(1))
    .imgImage.Picture = PictureFromBits(arBytes())
    rs.Close
    Set rs = Nothing
    I try to understand you code. How to start this?What is you table name?What is your field name?What the your field name data type?Do you store the image path location or the image name?

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Image path location

    Gambar in table "Penyakit" , I have many column name..Field name "Gambar" contains Image path location .


    Code:
    Private Sub ListView4_ItemClick(ByVal item As MSComctlLib.ListItem)
        penyakittable.Close
        penyakittable.Open "Select * from penyakit order by id asc", conpenyakit, adOpenDynamic, adLockOptimistic
        penyakittable.MoveFirst
        penyakittable.Move CLng(item.Index - 1)
        sTarikh = item.Text
        Command43.Enabled = True
        Command42.Enabled = True
        Form18.getID = penyakittable.Fields("ID").Value & ""
       
        Text26.Text = penyakittable.Fields("Nama Penyakit").Value & ""
        Text27.Text = penyakittable.Fields("Penerangan").Value & ""
        Picture3.Cls
        Picture3.AutoRedraw = True
        Picture3.ScaleMode = vbPixels
        'Set Picture3 = Nothing
        On Error GoTo error3:
        Picture3.PaintPicture LoadPicture(penyakittable.Fields("Gambar")), 0, 0, 200, 200
        Exit Sub
    error3:
        If Err.Number = 481 Then ' jika tiada image maka
        Dim strImagePath As String
        strImagePath = App.Path & "\ancaman padi\NoImage.gif"
        Picture3.PaintPicture LoadPicture(strImagePath), 0, 0, 200, 200
        Else
        
        Exit Sub
        End If
       
       
    
    
    End Sub
    Attached Images Attached Images  

  13. #13
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Image path location

    Ok - one things at a time.

    First - you should not be storing the PATH and IMAGE NAME in the same field.

    Gambar should have just the image name.

    GAMBAR
    --------
    Hawar Seludang.jpg
    Hawar Bakteria.jpg
    Karah.jpg
    Reput Tangkai.jpg
    Penyakit merah Virus.jpg

    Since this is a "static" piece of information - it's what should be stored.

    Now the "path" should be in a different table.

    We happen to have a configuration table in our system - it's a two column table. It contains a "configuration key" and the "data value" for that key.

    If you do not have a table like this already - then simply create a table called ImagePath. It would only need a single column - and will only have a single row.

    To support your current path you would simply load into that table the value

    C:\PF\GUI\ancaman padi\PENYAKIT PADI\

    This would be the path your would store in that field.

    You would grab this path - probably just once when you app loads.

    And concatenate it with the image name from the field GAMBAR.

    Does this make sense?

    Now once you have this separation - you can change the value in the IMAGEPATH table at an install site to whatever you want.

    You can then think of enhancing this to support a value of:

    .\folder\subfolder

    When we load a path like that we take the .\ and replace it with the APP.PATH value. That's our "shorthand" - our trigger - that tells us that the path is not a full path but instead a path off of the APP.PATH.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Image path location

    Thank you all of you. I got answer. Actually I don't know how to store the application (app.path) in the database access. Now I found that it used like this .\

  15. #15
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] Image path location

    This is actually the line of code we use

    Code:
    If Left(strImagePath, 2) = ".\" Then strImagePath = App.Path & Mid(strImagePath, 2)
    strImagePathj is the string holding the file path to the images. We read that out of a recordset from the database.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width