| |  |  | Miembros: Mensajes: Temas: Online: Ultimo Miembro: | | |  | | | 
21-10-2007, 10:23:00
| | Junior Member Site Admin | | Registrado: oct 2007 Posts: 25
Créditos: 555 | | visualizar una imagen de la base de datos Hola a todos, estoy haciendo un prama con visual basic 6.0 y ado para visualizar imagenes de una base de datos acces97.
Alguien sabe como se visualizan las imagenes? esque yo no consigo que se me visualicen porque rs.Fields me retorna un null
If IsNull(rs.Fields(Campo_Imagen).Value) Then
GoTo error_Function
End If)
El codigo que tengo es el siguiente:
Public Function Leer_Imagen(ADO_Connection As ADODB.Connection, _
sql As String, _
Campo_Imagen As String) As Picture
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
On Error GoTo error_Function
Set rs = New ADODB.Recordset
Dim Stream As ADODB.Stream
' Llena el recordset
rs.Open sql, ADO_Connection, adOpenKeyset, adLockOptimistic
' Si no hay registros sale de la función y retorna como _
resultado un valor Nothing, es decir ninguna imagen
If rs.RecordCount = 0 Then
Set Leer_Imagen = Nothing
rs.Close
Set rs = Nothing
Exit Function
End If
' Nuevo objeto Stream para poder leer el campo de imagen
Set Stream = New ADODB.Stream
' Especifica el tipo de datos ( binario )
Stream.Type = adTypeBinary
Stream.Open
' verifica con la función IsNull que el campo no tenga _
un valor Nulo ya que si no da error, en ese caso sale de la función
If IsNull(rs.Fields(Campo_Imagen).Value) Then
GoTo error_Function
End If
' Graba los datos en el objeto stream
Stream.Write rs.Fields(Campo_Imagen).Value
' este método graba un archivo temporal en disco _
( en el app.path que luego se elimina )
Stream.SaveToFile App.Path & "\temp", adSaveCreateOverWrite
' Retorna la imagen a la función
Set Leer_Imagen = LoadPicture(App.Path & "\temp")
' Elimina el archivo temporal
Kill App.Path & "\temp"
'Cierra el recordset y el objeto Stream
If rs.State = adStateOpen Then
rs.Close
End If
If Not rs Is Nothing Then
Set rs = Nothing
End If
If Stream.State = adStateOpen Then
Stream.Close
End If
If Not Stream Is Nothing Then
Set Stream = Nothing
End If
Exit Function
error_Function:
If Err.Number <> 0 Then
MsgBox CStr(Err) & " " & Error, vbExclamation
' elimina el temporal
If Len(Dir(App.Path & "\temp")) Then
Kill App.Path & "\temp"
End If
End If
End Function | 
21-10-2007, 10:51:54
| | Buena Participación en el Foro | | Registrado: sep 2007 Posts: 88
Créditos: 487 | | ¿No seria mas facil que en la BD guardases simplemente la ruta donde esta almacenada la imagen y asi la cargases?
Saludos. | 
22-10-2007, 15:31:35
|  | Gran Participación en el Foro | | Registrado: dic 2006 Ubicación: Cancun,Quintana Roo Posts: 191
Créditos: 406 | | Puedes utilzar estas funciones que me paso hace mucho tiempo un amigo y que son las que utlizo para controlar imagenes Código: '------------------------------------------------------------------
'Código para grabar imagenes en campos de bases de datos
'------------------------------------------------------------------
Public Sub GuardarBinary(campoBinary As Field, unPicture As Image)
On Error GoTo GuardarBinary_Error
'Guardar el contenido del Picture en el campo de la base
Dim i As Integer
Dim Fragment As Integer, Fl As Long, Chunks As Integer
'NOTA:
'El recordset debe estar preparado para Editar o Añadir
'Guardar el contenido del picture en un fichero temporal
SavePicture unPicture.Picture, "pictemp"
'Leer el fichero y guardarlo en el campo
DataFile = FreeFile
Open "pictemp" For Binary Access Read As DataFile
Fl = LOF(DataFile) ' Longitud de los datos en el archivo
If Fl = 0 Then Close DataFile: Exit Sub
Chunks = Fl \ conChunkSize
Fragment = Fl Mod conChunkSize
ReDim Chunk(Fragment)
Get DataFile, , Chunk()
campoBinary.AppendChunk Chunk()
ReDim Chunk(conChunkSize)
For i = 1 To Chunks
Get DataFile, , Chunk()
campoBinary.AppendChunk Chunk()
Next i
Close DataFile
'Ya no necesitamos el fichero, así que borrarlo
On Local Error Resume Next
If Len(Dir$("pictemp")) Then
Kill "pictemp"
End If
Err = 0
GuardarBinary_Done:
Exit Sub
GuardarBinary_Error:
Call SysException.error(MODULE_NAME, "GuardarBinary")
Resume GuardarBinary_Done
End Sub
Public Function GetImage(ByVal Value As String, _
Optional ByVal fldIdentificacion As String = "Id", _
Optional ByVal fldContieneImagen As String = "Foto", _
Optional ByVal Catalog As String = "cEmpleados", _
Optional ByVal FName As String = "FotoE") As Boolean _
On Error GoTo GetImage_Error
Dim Strm As ADODB.Stream
Dim RS As ADODB.Recordset
Dim sSQL$
GetImage = False
If LenB(fldContieneImagen$) = 0 Then Exit Function
If LenB(Catalog$) = 0 Then Exit Function
If LenB(FName$) = 0 Then Exit Function
sSQL = "SELECT " & fldContieneImagen
sSQL = sSQL & " FROM " & BDOPE & Catalog
sSQL = sSQL & " WHERE"
sSQL = sSQL & " " & fldIdentificacion & "=" & Value
Set RS = DemiData.cnCentral.Execute(sSQL)
If Not RecordsetVacio(RS) Then
If Not IsNull(RS.Fields(fldContieneImagen)) Then
Set Strm = New ADODB.Stream
Strm.Type = adTypeBinary
Strm.Open
Strm.Write RS.Fields(fldContieneImagen).Value
Strm.SaveToFile FName, adSaveCreateOverWrite
GetImage = True
End If
End If
GetImage_Done:
RecordsetCierra RS
If Not Strm Is Nothing Then
Strm.Close
Set Strm = Nothing
End If
Exit Function
GetImage_Error:
Call SysException.error(MODULE_NAME, "GetImage")
Resume GetImage_Done
End Function
Public Function PutImage(ByVal FName As String, _
ByVal Value As Long, _
Optional ByVal fldIdentificacion As String = "id_maestros", _
Optional ByVal fldContieneImagen As String = "Foto", _
Optional ByVal Catalog As String = "Maestros", _
Optional ByVal FullSQL As String = vbNullString) As Boolean
On Error GoTo PutImage_Error
Dim Strm As ADODB.Stream
Dim RS As ADODB.Recordset
Dim sExistFile As String
Dim sSQL$
PutImage = False
If LenB(fldContieneImagen$) = 0 Then Exit Function
If LenB(Catalog$) = 0 Then Exit Function
If LenB(FName$) = 0 Then Exit Function
If LenB(FullSQL) Then
sSQL = FullSQL
Else
sSQL = "SELECT " & fldContieneImagen
sSQL = sSQL & " FROM " & BDOPE & Catalog
sSQL = sSQL & " WHERE"
sSQL = sSQL & " " & fldIdentificacion & "=" & Value
End If
RS.Open sSQL, DemiData.cnCentral, adOpenDynamic, adLockOptimistic
If Not RecordsetVacio(RS) Then
Set Strm = New ADODB.Stream
Strm.Type = adTypeBinary
Strm.Open
sExistFile = Dir$(FName)
If LenB(sExistFile$) > 0 Then
Strm.LoadFromFile FName
RS.Fields(fldContieneImagen).Value = Strm.Read
RS.Update
PutImage = True
End If
End If
PutImage_Done:
RecordsetCierra RS
If Not Strm Is Nothing Then
Strm.Close
Set Strm = Nothing
End If
Exit Function
PutImage_Error:
Call SysException.error(MODULE_NAME, "PutImage")
Resume PutImage_Done
End Function
__________________ Alex malm | 
03-11-2007, 16:37:34
| | Junior Member Site Admin | | Registrado: oct 2007 Posts: 16
Créditos: 655 | | algo sencillo Híjole, no es muy complejo pero espero que te sirva
agrégale a tu base de datos un campo llamado número, y la base con tus datos queda así.
número foto nombre etc.
1 1.jpg fulano ...
pon un timer
y dentro de el llama un control con el número de ese campo más el de la imagen
imgFoto.Picture = LoadPicture(app.path "lblNúmero.Caption" & ".jpg")
eso sí los nombres de los archivos de las imágenes se deben llamar igual que el número. | 
03-11-2007, 21:18:34
|  | Moderador | | Registrado: nov 2007 Ubicación: Argentina Posts: 799
Créditos: 5.826 | |
__________________ Todos somos ignorantes; lo que pasa es que no todos ignoramos las mismas cosas - Albert Einstein | 
04-11-2007, 11:58:26
| | Buena Participación en el Foro | | Registrado: mar 2007 Posts: 75
Créditos: 1.673 | | yo te doy mi opinion que creo que es mucho mas sencillo que todo eso, creas un campo en la base de datos de acces97 con la ruta de donde esta situada la imagen y luego en el reposition del data, es decir:
Private Sub Data1_Reposition()
Dim caminoAs String
If Data1.Recordset.EOF Then Exit Sub
If Data1.Recordset.BOF Then Exit Sub
camino= Data1.Recordset.Fields(el campo donde este la ruta de la imagen)
Image1.Picture = LoadPicture(camino)
End Sub
de esta forma se te cargara la imagen en el image que hayas creau, espero que te sirva, un saludo | 
10-11-2007, 10:58:28
| | Gran Participación en el Foro | | Registrado: nov 2004 Posts: 215
Créditos: 6.464 | | como imprimir el reporte con la imagen Me eto en este post pues utilizo la opción de guardar las imagenes como archivos jpg. Y para mis forms va bien pero ¿Como puedo hacer que se impriman en un reporte?
Uso crystal reports y no veo la manera de incluir una imagen en el reporte en tiempo de ejecución
Gracias |
Normas de Publicación
| no Puedes crear nuevos temas no Puedes responder a temas no Puedes adjuntar archivos no Puedes editar tus mensajes Código [IMG] está habilitado Código HTML está deshabilitado | | | La franja horaria es GMT. Ahora son las 22:30:57.
Powered by vBulletin® Version 3.6.8 Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 |  |