Results 1 to 13 of 13

Thread: How to set picture in ImageBox

  1. #1

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    How to set picture in ImageBox

    i have picture in RS(2) how can i set this picture into Image1 ...??

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to set picture in ImageBox

    what is RS(2) ?

  3. #3
    Member
    Join Date
    Apr 2005
    Posts
    51

    Re: How to set picture in ImageBox

    some what confused. but to set an image in a picturebox. in the properties u go to picture option and click on it then click on the ... to the right then it brings up the browse thing to find the picture. was that wut u were asking?

  4. #4

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to set picture in ImageBox

    Quote Originally Posted by dglienna
    what is RS(2) ?
    it is RECORDSET.... and 2 is index of COLUMN....
    I m using IMAGE CONTROL

  5. #5
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: How to set picture in ImageBox

    If the object in RS(2) is a StdPicture, then use:

    Set Image1 = RS(2)

  6. #6

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to set picture in ImageBox

    When i was trying
    Set Image1.Datasource =rs <=== Type MisMatch Error
    Set Image1.Datasource =rs <=== Type MisMatch Error


    And now
    Set Image1 =rs(2) <=== Invalid Picture Error

    ..?

  7. #7
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: How to set picture in ImageBox

    What exactly is in RS(2)? Is it a string path, or a picture object, or something else?

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

    Re: How to set picture in ImageBox

    I will give give logic I use but don't ask me to modify it for you - I'm sure you will figure it out how it works :
    VB Code:
    1. Option Explicit
    2.  
    3. Public Const MAX_PATH = 260
    4. Public Const BLOCK_SIZE = 10000
    5.  
    6. Private Declare Function GetTempFileName Lib "kernel32" _
    7.     Alias "GetTempFileNameA" _
    8.     (ByVal lpszPath As String, ByVal lpPrefixString As String, _
    9.      ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
    10.  
    11. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
    12.     (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    13.  
    14. Public Sub ExtractImage(rstTemp As ADODB.Recordset, sTitle As String, pctTemp As PictureBox)
    15. '============================================================================================
    16. Dim bytes() As Byte
    17. Dim file_name As String
    18. Dim file_num As Integer
    19. Dim file_length As Long
    20. Dim num_blocks As Long
    21. Dim left_over As Long
    22. Dim block_num As Long
    23. Dim hgt As Single
    24.  
    25. On Error GoTo ErrHandler
    26.  
    27.     'me.imgPhoto.Visible = False
    28.     Screen.MousePointer = vbHourglass
    29.     DoEvents
    30.    
    31.     rstTemp.Find "Title='" & sTitle & "'"
    32.    
    33.     ' Get a temporary file name.
    34.     file_name = TemporaryFileName()
    35.    
    36.     ' Open the file.
    37.     file_num = FreeFile
    38.     Open file_name For Binary As #file_num
    39.         ' Copy the data into the file.
    40.         file_length = rstTemp("fImageSize")
    41.         num_blocks = file_length / BLOCK_SIZE
    42.         left_over = file_length Mod BLOCK_SIZE
    43.        
    44.         'get all chunks and write then to a temp file
    45.         For block_num = 1 To num_blocks
    46.             bytes() = rstTemp("fImage").GetChunk(BLOCK_SIZE)
    47.             Put #file_num, , bytes()
    48.         Next block_num
    49.         If left_over > 0 Then
    50.             bytes() = rstTemp("fImage").GetChunk(left_over)
    51.             Put #file_num, , bytes()
    52.         End If
    53.     Close #file_num
    54.    
    55.     'load image
    56.     pctTemp.Picture = LoadPicture(file_name)
    57.    
    58.     Screen.MousePointer = vbDefault
    59.     Exit Sub
    60.  
    61. ErrHandler:
    62. '-----------
    63.  
    64.     Debug.Print Err.Description
    65.     Err.Clear
    66.     Resume Next
    67.  
    68. End Sub
    69.  
    70. Public Function TemporaryFileName() As String
    71. '==============================================
    72. Dim temp_path As String
    73. Dim temp_file As String
    74. Dim length As Long
    75.  
    76.     ' Get the temporary file path.
    77.     temp_path = Space$(MAX_PATH)
    78.     length = GetTempPath(MAX_PATH, temp_path)
    79.     temp_path = Left$(temp_path, length)
    80.  
    81.     ' Get the file name.
    82.     temp_file = Space$(MAX_PATH)
    83.     GetTempFileName temp_path, "per", 0, temp_file
    84.     TemporaryFileName = Left$(temp_file, InStr(temp_file, Chr$(0)) - 1)
    85.  
    86. End Function

  9. #9

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to set picture in ImageBox

    rs(2) contains PICTURE OBJECT
    i have table1
    fieldname =picture
    this field data type = OLE Object

  10. #10

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to set picture in ImageBox

    Quote Originally Posted by vbPoet
    rs(2) contains PICTURE OBJECT
    i have table1
    fieldname =picture
    this field data type = OLE Object
    RhinO i appreciates your effort ...!


    But i think there should be some simple way of it ....
    there is OLE OBJECT in rs(2)
    and i want to get that picture displayed in IMAGE CONTROL ...

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to set picture in ImageBox

    vbPoet, there is no "simple" way to do it. What RhinoBull posted is good and is what you need. You should take a look at it again.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: How to set picture in ImageBox

    Quote Originally Posted by RobDog888
    vbPoet, there is no "simple" way to do it. What RhinoBull posted is good and is what you need. You should take a look at it again.

    Thx Robert
    if there is no simple way then i consider RHINO's Code.
    Anyway U & RHINO are herO ...


    Can you tell me AT LAST y there is not any simple way of doing So ...?

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to set picture in ImageBox

    Well, there may be using a data "type" control but I never use then since they are eveil
    If you were using ADO then I do believe its easier with the ADODC data control to bind the datasource of the image control to it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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