How To save image in MDB from image control.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How To save image in MDB from image control.

  1. #1
    Join Date
    Feb 2007
    Posts
    16

    How To save image in MDB from image control.

    hi
    Good Evening

    accully, i want to save picture from image control.(it's small pixel size)
    pupose : make small mdb size.

    Note : do not save picture from direct file.(it's Large file size)

    if possible any other idea for make small saving size in database.
    pls say...

    Thanks...friend
    -LiveSys
    Attached Images Attached Images

  2. #2
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    I took some old code that used the AppendChunck, and GetChunk of the ADO recordset object to get and store an image from the database to a file. I converted it to use a byte array. So now it reads and stores the image to and from a byte array. So when you extract the image data to a byte array you can store it in your database and of course extracting the bytes from the database and loading them into you image control. I have NOT tested this code, so you may run into errors. If so let me know and I will help you debug this. Also if you don't know how to get and put the image into and out of a byte array, let me know, I know I have some code arround that does this. One more thought is that if you have any trouble passing the byte array as a parameter to the SetDbPhotoBytes function, try changing it to a variant instead of a byte array. ,,,bytes() As Byte becomes ,,,bytes As Variant. It should work either way but I have run into problems with passing arrays as parameters and whenever I do if I change it a type variant the the problem goes away.

    The GetDbPhotoBytes returns the byte array with the image data in it.
    The SetDbPhotoBytes returns the number of bytes stored, so you can test it to see if anything got stored. >0 means data got stored.


    Code:
    Public Function GetDbPhotoBytes(rstMain As Recordset, FieldName As String) As Variant
      On Error GoTo Er
      Dim PicSize As Long
      Dim bytes() As Byte
      
      
      'PicSize = rstMain(FieldName).DefinedSize   'this might work better, not sure ?
      PicSize = rstMain(FieldName).ActualSize
      ReDim bytes(PicSize)
      bytes() = rstMain(FieldName).GetChunk(PicSize)
        
      GetDbPhotoBytes = bytes()
      
    Ex:
      Erase bytes
      Exit Function
      
    Er:
      MsgBox Err.Description
      Resume Ex
    
    End Function
    
    Public Function SetDbPhoto(rstMain As Recordset, FieldName As String, bytes() As Byte) As Long
      On Error GoTo Er
      Dim PicSize As Long
    
      'if bytes is defined as (1 To 10): 10 -1 + 1 = 10 or (0 To 9) 9 - 0 + 1 = 10 ...
      PicSize = UBound(bytes) - LBound(bytes) + 1
      If PicSize > 0 Then
        rstMain(FieldName).AppendChunk bytes()
      End If
      
    Ex:
      SetDbPhoto = PicSize
      Exit Function
    
    Er:
      MsgBox Err.Description
      Resume Ex
    
    End Function

Similar Threads

  1. Data Report Designer Image Control
    By Filbert in forum VB Classic
    Replies: 2
    Last Post: 03-06-2006, 11:21 AM
  2. Save Image in to a table
    By Dmitry in forum VB Classic
    Replies: 7
    Last Post: 06-27-2002, 12:44 PM
  3. Replies: 4
    Last Post: 01-16-2002, 09:16 AM
  4. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 12:45 PM
  5. How can I save a Image to disk
    By Abel Castellanos in forum Java
    Replies: 0
    Last Post: 01-06-2001, 12:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center