
Iniciado por
Jumper
"dcraw -e" extrae el jpeg incrustado que tiene cada raw, puedes extraer todas las miniaturas de jpeg de cada raw y luego tu programa las leerá sin problemas como un jpeg más. Necesitas utilizar un programa externo como dcraw para ello, pero trabaja integramente en linea de comandos y como ves la solución sería muy sencilla.
Puedes llamar a DCRAW desde VB muy fácilmente:
Código:
Option Explicit
Option Base 1
' Declaración de tipos necesarios para el control de procesos
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
' Esta función sirve para lanzar dcraw.exe (equivale a Shell)
' http://msdn2.microsoft.com/en-us/library/ms682425(VS.85).aspx
Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Any, _
lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
' Obtenemos handler al ejecutable lanzado identificado por hObject (ID de proceso)
Private Declare Function OpenProcess Lib "kernel32.dll" _
(ByVal dwAccess As Long, _
ByVal fInherit As Integer, _
ByVal hObject As Long) As Long
' Supongo que fuerza la finalización del proceso (no la usamos)
Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
' Cierra los procesos
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
' Testea si el proceso hProcess sigue en ejecución
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
' Pausa en milisegundos (podría sustituir a un Timer)
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_CLASS = &H20&
' Función de revelado
Function LlamadaDCRAW()
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const PROCESS_QUERY_INFORMATION = &H400
Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO
Dim sNull As String
Dim lSuccess As Long
Dim lRetValue As Long
Dim hproc As Long
Dim ok As Long
Dim exitCode As Long
Const STILL_ACTIVE = &H103 ' En decimal 259
'http://support.microsoft.com/kb/129797
sInfo.cb = Len(sInfo)
' Lanzamos DCRAW obteniendo en pInfo la información del proceso creado (pInfo.dwProcessId)
' http://msdn2.microsoft.com/en-us/library/ms682425(VS.85).aspx
lSuccess = CreateProcess(sNull, _
"c:\dcraw.exe -v -T -4 c:\r\1.cr2 c:\r\2.cr2 c:\r\3.cr2", _
ByVal 0&, _
ByVal 0&, _
1&, _
NORMAL_PRIORITY_CLASS, _
ByVal 0&, _
sNull, _
sInfo, _
pInfo)
' Pendiente: qué hacer si lSuccess es = 0
' Obtenemos handler al ejecutable lanzado identificado por pInfo.dwProcessId
hproc = OpenProcess(STANDARD_RIGHTS_REQUIRED Or PROCESS_QUERY_INFORMATION, False, pInfo.dwProcessId)
' Detectamos finalización del proceso con exitCode<>259
While (hproc)
ok = GetExitCodeProcess(hproc, exitCode)
'http://vbnet.mvps.org/index.html?code/faq/getexitcprocess.htm
If exitCode <> STILL_ACTIVE Then GoTo Salir
'http://www.developerfusion.co.uk/show/119/
Sleep (100)
Wend
Salir:
lRetValue = CloseHandle(pInfo.hThread)
lRetValue = CloseHandle(pInfo.hProcess)
End Function
Yo lo hago más a lo bruto, con el Shell, pero quiero migrarlo un día a la otra forma:
Código:
Shell "c:\dcraw.exe -e foto.cr2", vbHide
pero es mejor el código que te he puesto antes porque detecta cuando el proceso DCRAW ha terminado. Aunque si solo vas a extraer el JPEG, como eso no tarda nada puedes hacer esta llamada que es muy simple, esperar un par de segundos, y luego leer el archivo foto.thumb.jpg en la misma ruta del CR2.
Salu2
Marcadores