The code below works just fine on WinXP and Vista.
( extensions: jpg, tif, gif, bmp, png, nef )
Windows 7, all versions, gives an error code of 3.(file not found) for NEF files.
( other extensions: jpg, tif, gif, bmp, png work.)
The NIKON Codec is install properly on all systems - XP, Vista and Windows 7.
Any suggestion woul be appreciated.
Compiler 10.02
%UNICODE = 1
#INCLUDE "c:\pbwin10\WinApi_205\GDIPLUS.INC" - Jose's Includes
'------------------------------------------------------------------------------
SUB GDIP_GetImageThumbnail(BYVAL hdc AS DWORD, BYVAL W AS LONG, BYVAL H AS LONG, BYVAL Who AS LONG)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL strFileName AS WSTRINGZ * 160
LOCAL pImage AS DWORD
LOCAL nWidth AS DWORD
LOCAL nHeight AS DWORD
LOCAL A AS SINGLE
LOCAL B AS SINGLE
LOCAL C AS SINGLE
LOCAL D AS SINGLE
hStatus = GdipCreateFromHDC(hdc, pGraphics)
strFileName = ThePic 'Global
hStatus = GdipLoadImageFromFile(strFileName, pImage) - - - - - > hStatus = 3
'
IF Angle > 0 THEN
SELECT CASE AS LONG Angle
CASE 90
hStatus = GdipImageRotateFlip(pImage, %ROTATE90FLIPNONE)
CASE 180
hStatus = GdipImageRotateFlip(pImage, %ROTATE180FLIPNONE)
CASE 270
hStatus = GdipImageRotateFlip(pImage, %ROTATE270FLIPNONE)
END SELECT
END IF
'
hStatus = GdipGetImageWidth(pImage, nWidth)
hStatus = GdipGetImageHeight(pImage, nHeight)
A = nWidth
B = nHeight
C = W
D = H
IF nWidth > W THEN
IF nWidth => nHeight THEN
nWidth = nWidth * (C / A)
nHeight = nHeight * (C / A)
END IF
END IF
IF nHeight > H THEN
IF nHeight => nWidth THEN
nWidth = nWidth * (D / B)
nHeight = nHeight * (D / B)
END IF
END IF
'
hStatus = GdipDrawImageRect(pGraphics, pImage, 0, 0, nWidth, nHeight)
'
IF pImage THEN GdipDisposeImage(pImage)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
GRAPHIC REDRAW
END SUB
'------------------------------------------------------------------------------
try these versions for pbwin 10 :)
1) sdk modus
2) ddt modus
to 1) so far as I know the declare function has changed for "GdipLoadImageFromFile" from pbwin 9 to pbwin 10. other side I suppose the main problem concerning the "byref" parameters of "GdipLoadImageFromFile" line as
hStatus = GdipLoadImageFromFile(BYVAL STRPTR(strFileName), BYVAL VARPTR(pImage) )
'DECLARE FUNCTION GdipLoadImageFromFile IMPORT "GDIPLUS.DLL" ALIAS "GdipLoadImageFromFile" ( _
' BYREF filename AS WSTRINGZ _ ' __in GDIPCONST WCHAR *filename
' , BYREF image AS DWORD _ ' __out GpImage **image
' ) AS LONG ' GpStatus
the correct code looks like this one:
' ========================================================================================
' GdipGetImageThumbnail
' ========================================================================================
' SED_PBWIN
#COMPILE EXE
#DIM ALL
#INCLUDE "GDIPLUS.INC"
'DECLARE FUNCTION GdipLoadImageFromFile IMPORT "GDIPLUS.DLL" ALIAS "GdipLoadImageFromFile" ( _
' BYREF filename AS WSTRINGZ _ ' __in GDIPCONST WCHAR *filename
' , BYREF image AS DWORD _ ' __out GpImage **image
' ) AS LONG ' GpStatus
' ========================================================================================
' The following example creates a rotation matrix and passes the address of that matrix to
' the GdipSetWorldTransform function. The code calls the GdipDrawRectangle function to
' draw a rotated rectangle.
' ========================================================================================
SUB GDIP_GetImageThumbnail (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL strFileName AS STRING
LOCAL pImage AS DWORD
LOCAL nWidth AS DWORD
LOCAL nHeight AS DWORD
LOCAL pThumbnail AS DWORD
LOCAL nThumbnailWidth AS DWORD
LOCAL nThumbnailHeight AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create an image and a thumbnail of the image.
strFileName = UCODE$("climber.jpg")
hStatus = GdipLoadImageFromFile(BYVAL STRPTR(strFileName), BYVAL VARPTR(pImage) )
hStatus = GdipGetImageThumbnail(pImage, 40, 40, pThumbnail, %NULL, %NULL)
' // Draw the original and the thumbnail images.
hStatus = GdipGetImageWidth(pImage, nWidth)
hStatus = GdipGetImageHeight(pImage, nHeight)
hStatus = GdipDrawImageRect(pGraphics, pImage, 10, 10, nWidth, nHeight)
hStatus = GdipGetImageWidth(pThumbnail, nThumbnailWidth)
hStatus = GdipGetImageHeight(pThumbnail, nThumbnailHeight)
hStatus = GdipDrawImageRect(pGraphics, pThumbnail, 200, 10, nThumbnailWidth, nThumbnailHeight)
' // Cleanup
IF pThumbnail THEN GdipDisposeImage(pThumbnail)
IF pImage THEN GdipDisposeImage(pImage)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
LOCAL hr AS LONG
LOCAL hWndMain AS DWORD
LOCAL hCtl AS DWORD
LOCAL hFont AS DWORD
LOCAL wcex AS WndClassEx
LOCAL szClassName AS ASCIIZ * 80
LOCAL rc AS RECT
LOCAL szCaption AS ASCIIZ * 255
LOCAL nLeft AS LONG
LOCAL nTop AS LONG
LOCAL nWidth AS LONG
LOCAL nHeight AS LONG
LOCAL token AS DWORD
LOCAL StartupInput AS GdiplusStartupInput
' Initialize GDI+
StartupInput.GdiplusVersion = 1
hr = GdiplusStartup(token, StartupInput, BYVAL %NULL)
IF hr THEN
MSGBOX "Error initializing GDI+"
EXIT FUNCTION
END IF
hFont = GetStockObject(%ANSI_VAR_FONT)
' Register the window class
szClassName = "MyClassName"
wcex.cbSize = SIZEOF(wcex)
wcex.style = %CS_HREDRAW OR %CS_VREDRAW
wcex.lpfnWndProc = CODEPTR(WndProc)
wcex.cbClsExtra = 0
wcex.cbWndExtra = 0
wcex.hInstance = hInstance
wcex.hCursor = LoadCursor (%NULL, BYVAL %IDC_ARROW)
wcex.hbrBackground = GetStockObject(%WHITE_BRUSH)
wcex.lpszMenuName = %NULL
wcex.lpszClassName = VARPTR(szClassName)
wcex.hIcon = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Sample, if resource icon: LoadIcon(hInst, "APPICON")
wcex.hIconSm = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Remember to set small icon too..
RegisterClassEx wcex
' Window caption
szCaption = "GdipGetImageThumbnail"
' Retrieve the nSize of the working area
SystemParametersInfo %SPI_GETWORKAREA, 0, BYVAL VARPTR(rc), 0
' Calculate the position and nSize of the window
nWidth = (((rc.nRight - rc.nLeft)) + 2) * 0.55 ' 55% of the client screen width
nHeight = (((rc.nBottom - rc.nTop)) + 2) * 0.50 ' 50% of the client screen height
nLeft = ((rc.nRight - rc.nLeft) \ 2) - nWidth \ 2
nTop = ((rc.nBottom - rc.nTop) \ 2) - (nHeight \ 2)
' Create a window using the registered class
hWndMain = CreateWindowEx(%WS_EX_CONTROLPARENT, _ ' extended style
szClassName, _ ' window class name
szCaption, _ ' window caption
%WS_OVERLAPPEDWINDOW OR _
%WS_CLIPCHILDREN, _ ' window style
nLeft, _ ' initial x position
nTop, _ ' initial y position
nWidth, _ ' initial x nSize
nHeight, _ ' initial y nSize
%NULL, _ ' parent window handle
0, _ ' window menu handle
hInstance, _ ' program instance handle
BYVAL %NULL) ' creation parameters
' Show the window
ShowWindow hWndMain, nCmdShow
UpdateWindow hWndMain
' Message handler loop
LOCAL Msg AS tagMsg
WHILE GetMessage(Msg, %NULL, 0, 0)
IF ISFALSE IsDialogMessage(hWndMain, Msg) THEN
TranslateMessage Msg
DispatchMessage Msg
END IF
WEND
' Shutdown GDI+
GdiplusShutdown token
FUNCTION = msg.wParam
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
LOCAL hDC AS DWORD
LOCAL ps AS PAINTSTRUCT
SELECT CASE wMsg
CASE %WM_COMMAND
' -------------------------------------------------------
' Messages from controls and menu items are handled here.
' -------------------------------------------------------
SELECT CASE LOWRD(wParam)
CASE %IDCANCEL
IF HIWRD(wParam) = %BN_CLICKED THEN
SendMessage hWnd, %WM_CLOSE, 0, 0
FUNCTION = 0
EXIT FUNCTION
END IF
END SELECT
CASE %WM_SYSCOMMAND
' Capture this message and send a WM_CLOSE message
IF (wParam AND &HFFF0) = %SC_CLOSE THEN
SendMessage hWnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
CASE %WM_PAINT
hDC = BeginPaint(hWnd, ps)
GDIP_GetImageThumbnail hDC
EndPaint(hWnd, ps)
CASE %WM_DESTROY
PostQuitMessage 0 ' This function closes the main window
FUNCTION = 0 ' by sending zero to the main message loop
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
but this was tested only for win xp os system ;) perhaps this example can help, I don't know. but I have noticed some declare functions of gdip include files has changed from pbwin 9 to pbwin 10.
to 2) as I've seen you're using DDT modus ? and you have used a complete other setup for original ddt modus for "gdip_getImageThumbnail" in original mode:
gdip_getImageThumbnail (ddt modus: correct version for pbwin 10):
' ========================================================================================
' GdipGetImageThumbnail
' ========================================================================================
' SED_PBWIN
#COMPILE EXE
#DIM ALL
#INCLUDE "GDIPLUS.INC"
' ========================================================================================
' The following example creates a rotation matrix and passes the address of that matrix to
' the GdipSetWorldTransform function. The code calls the GdipDrawRectangle function to
' draw a rotated rectangle.
' ========================================================================================
SUB GDIP_GetImageThumbnail (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL strFileName AS STRING
LOCAL pImage AS DWORD
LOCAL nWidth AS DWORD
LOCAL nHeight AS DWORD
LOCAL pThumbnail AS DWORD
LOCAL nThumbnailWidth AS DWORD
LOCAL nThumbnailHeight AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create an image and a thumbnail of the image.
strFileName = UCODE$("climber.jpg")
hStatus = GdipLoadImageFromFile(Byval STRPTR(strFileName), byval varptr(pImage) )
hStatus = GdipGetImageThumbnail(pImage, 40, 40, pThumbnail, %NULL, %NULL)
' // Draw the original and the thumbnail images.
hStatus = GdipGetImageWidth(pImage, nWidth)
hStatus = GdipGetImageHeight(pImage, nHeight)
hStatus = GdipDrawImageRect(pGraphics, pImage, 10, 10, nWidth, nHeight)
hStatus = GdipGetImageWidth(pThumbnail, nThumbnailWidth)
hStatus = GdipGetImageHeight(pThumbnail, nThumbnailHeight)
hStatus = GdipDrawImageRect(pGraphics, pThumbnail, 200, 10, nThumbnailWidth, nThumbnailHeight)
' // Cleanup
IF pThumbnail THEN GdipDisposeImage(pThumbnail)
IF pImage THEN GdipDisposeImage(pImage)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
LOCAL hr AS LONG
LOCAL hDlg AS DWORD
LOCAL token AS DWORD
LOCAL StartupInput AS GdiplusStartupInput
' Initialize GDI+
StartupInput.GdiplusVersion = 1
hr = GdiplusStartup(token, StartupInput, BYVAL %NULL)
IF hr THEN
MSGBOX "Error initializing GDI+"
EXIT FUNCTION
END IF
DIALOG NEW 0, "GdipGetImageThumbnail", , , 270, 170, %WS_OVERLAPPED OR %WS_THICKFRAME OR %WS_SYSMENU OR _
%WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_VISIBLE OR %DS_CENTER TO hDlg
DIALOG SET COLOR hDlg, %BLACK, %WHITE
DIALOG SHOW MODAL hDlg, CALL DlgProc
' Shutdown GDI+
GdiplusShutdown token
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CALLBACK FUNCTION DlgProc() AS LONG
LOCAL hDC AS DWORD
LOCAL ps AS PAINTSTRUCT
SELECT CASE CBMSG
CASE %WM_COMMAND
SELECT CASE CBCTL
CASE %IDCANCEL
IF CBCTLMSG = %BN_CLICKED THEN DIALOG END CBHNDL, 0
END SELECT
CASE %WM_PAINT
hDC = BeginPaint(CBHNDL, ps)
GDIP_GetImageThumbnail hDC
EndPaint(CBHNDL, ps)
END SELECT
END FUNCTION
' ========================================================================================
in your code example there's missing to load the image file by name ( strFileName = UCODE$("climber.jpg") ). I've not tested your example.
best regards, frank
Quote
Windows 7, all versions, gives an error code of 3.(file not found) for NEF files.
( other extensions: jpg, tif, gif, bmp, png work.)
Error code 3 is Out of memory, not File not found.
Found this:
http://stackoverflow.com/questions/1644108/win7-out-of-memory-exception-on-image-fromfile