Hi.
I can't understand (because of my lack of experience surely) why I have mistakes, strangely for me, using this program I'm trying to do.
A simple program that opens an image for me and saves it, perhaps reducing the size or quality... For now, I was just sketching...
Thank you.
'#case capital
'def NULL null
uses filedialogs
uses MinWin
uses ImgWin
#lookahead ' for procedures
'// variabili per fileopen
indexbase 1
string sep=chr(0)
string filter="jpg"+sep+"*.jpg"
sys tipogui
tipogui=OFN_EXPLORER or OFN_ALLOWMULTISELECT
typedef void *pvoid
'
sys hstatus
sys pGraphics,pImage,pBitmap,pStream,pStreamo,pThumbnail
wstring strFileName
sys nThumbnailWidth,nThumbnailHeight,nwidth,nheight
'
'hStatus = GdipCreateFromHDC hdc, pGraphics
'
' // Create an image and a thumbnail of the image.
'
'strFileName = "../images/Dawn1815.jpg"
strFileName=FileDialog("C:\temp\1",filter,"open","", 0,tipogui,0)
if strFileName ="" then ExitProcess(0)
hStatus = GdipLoadImageFromFile strFileName, 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 = GdipDrawImageRectI pGraphics, pImage, 10, 60, nWidth, nHeight
hStatus = GdipGetImageWidth pThumbnail, nThumbnailWidth
hStatus = GdipGetImageHeight pThumbnail, nThumbnailHeight
hStatus = GdipDrawImageRect pGraphics, pThumbnail, 10, 10, nThumbnailWidth, nThumbnailHeight
'
' // Cleanup
'
if pThumbnail
GdipDisposeImage pThumbnail
endif
if pImage
GdipDisposeImage pImage
endif
if pGraphics
GdipDeleteGraphics pGraphics
endif
Nicola
You not say what kind of errors you have
you just say ..i have mistakes ..hmmm
but what and where ?
or i really miss something ::)
ok i found this :
uses filedialog
u use filedialogs ..probably .include should be renamed
CF_BIMAP const not found ::)
this one compile with 604
'#case capital
'def NULL null
uses filedialog
uses MinWin
uses ImgWin
#lookahead ' for procedures
'// variabili per fileopen
indexbase 1
string sep=chr(0)
string filter="jpg"+sep+"*.jpg"
sys tipogui
tipogui = OFN_EXPLORER or OFN_FILEMUSTEXIST
typedef void *pvoid
'
sys hstatus
sys pGraphics,pImage,pBitmap,pStream,pStreamo,pThumbnail
wstring strFileName
sys nThumbnailWidth,nThumbnailHeight,nwidth,nheight
'
'hStatus = GdipCreateFromHDC hdc, pGraphics
'
' // Create an image and a thumbnail of the image.
'
'strFileName = "../images/Dawn1815.jpg"
strFileName=FileDialog("C:\temp\1",filter,"open","", 0,tipogui,0)
if strFileName ="" then ExitProcess(0)
hStatus = GdipLoadImageFromFile strFileName, pImage
hStatus = GdipGetImageThumbnail pImage, 40, 40, pThumbnail, 0, 0
'
' // Draw the original and the thumbnail images.
'
hStatus = GdipGetImageWidth pImage, nWidth
hStatus = GdipGetImageHeight pImage, nHeight
hStatus = GdipDrawImageRectI pGraphics, pImage, 10, 60, nWidth, nHeight
hStatus = GdipGetImageWidth pThumbnail, nThumbnailWidth
hStatus = GdipGetImageHeight pThumbnail, nThumbnailHeight
hStatus = GdipDrawImageRect pGraphics, pThumbnail, 10, 10, nThumbnailWidth, nThumbnailHeight
'
' // Cleanup
'
if pThumbnail
GdipDisposeImage pThumbnail
end if
if pImage
GdipDisposeImage pImage
end if
if pGraphics
GdipDeleteGraphics pGraphics
end if
imgwin.inc
#case capital
'AD HOC DEFINITIONS
'==================
#define WINGDIPAPI
#define const
#define GDIPCONST
#define __out
#define __in
#define __inout
'
typedef bool BOOL
typedef byte BYTE
typedef word WORD
typedef sys DebugEventProc,HBITMAP,HPALETTE
typedef void GpGraphics, GpImage,IStream,GpBitmap,*LPVOID
typedef single REAL
typedef sys ULONG_PTR, HDC, GpStatus, ImageType
typedef long LONG,INT,UINT
typedef dword DWORD,UINT,UINT32,ARGB
typedef wchar WCHAR
def CF_BITMAP 2
def CF_PALETTE 9
Type RECT
Left as INT
Top as INT
Right as INT
Bottom as INT
End Type
% OFN_EXPLORER = 0x00080000
% OFN_FILEMUSTEXIST = 0x00001000
'================
'GDIPLUS MINI API
'================
'Pixel Formats
'http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx
typedef INT PixelFormat;
#define PixelFormatIndexed 0x00010000 // Indexes into a palette
#define PixelFormatGDI 0x00020000 // Is a GDI-supported format
#define PixelFormatAlpha 0x00040000 // Has an alpha component
#define PixelFormatPAlpha 0x00080000 // Pre-multiplied alpha
#define PixelFormatExtended 0x00100000 // Extended color 16 bits/channel
#define PixelFormatCanonical 0x00200000
#define PixelFormatUndefined 0
#define PixelFormatDontCare 0
#define PixelFormat1bppIndexed (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI)
#define PixelFormat4bppIndexed (2 | ( 4 << 8) | PixelFormatIndexed | PixelFormatGDI)
#define PixelFormat8bppIndexed (3 | ( 8 << 8) | PixelFormatIndexed | PixelFormatGDI)
#define PixelFormat16bppGrayScale (4 | (16 << 8) | PixelFormatExtended)
#define PixelFormat16bppRGB555 (5 | (16 << 8) | PixelFormatGDI)
#define PixelFormat16bppRGB565 (6 | (16 << 8) | PixelFormatGDI)
#define PixelFormat16bppARGB1555 (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI)
#define PixelFormat24bppRGB (8 | (24 << 8) | PixelFormatGDI)
#define PixelFormat32bppRGB (9 | (32 << 8) | PixelFormatGDI)
#define PixelFormat32bppARGB (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)
#define PixelFormat32bppPARGB (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI)
#define PixelFormat48bppRGB (12 | (48 << 8) | PixelFormatExtended)
#define PixelFormat64bppARGB (13 | (64 << 8) | PixelFormatAlpha | PixelFormatCanonical | PixelFormatExtended)
#define PixelFormat64bppPARGB (14 | (64 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatExtended)
#define PixelFormat32bppCMYK (15 | (32 << 8))
#define PixelFormatMax 16
typedef struct tagGDIStartup {
UINT32 GdiplusVersion;
DebugEventProc DebugEventCallback;
BOOL SuppressBackgroundThread;
BOOL SuppressExternalCodecs;
} GdiplusStartupInput;
typedef void *NotificationHookProc,*NotificationUnhookProc
'typedef sys NotificationHookProc,NotificationUnhookProc
typedef struct {
NotificationHookProc NotificationHook;
NotificationUnhookProc NotificationUnhook;
} GdiplusStartupOutput;
'Status
'======
typedef enum {
Ok = 0,
GenericError = 1,
InvalidParameter = 2,
OutOfMemory = 3,
ObjectBusy = 4,
InsufficientBuffer = 5,
NotImplemented = 6,
Win32Error = 7,
WrongState = 8,
Aborted = 9,
FileNotFound = 10,
ValueOverflow = 11,
AccessDenied = 12,
UnknownImageFormat = 13,
FontFamilyNotFound = 14,
FontStyleNotFound = 15,
NotTrueTypeFont = 16,
UnsupportedGdiplusVersion = 17,
GdiplusNotInitialized = 18,
PropertyNotFound = 19,
PropertyNotSupported = 20,
ProfileNotFound = 21
} Status;
enum ImageFlags
{
ImageFlagsNone = 0,
// Low-word: shared with SINKFLAG_x
ImageFlagsScalable = 0x0001,
ImageFlagsHasAlpha = 0x0002,
ImageFlagsHasTranslucent = 0x0004,
ImageFlagsPartiallyScalable = 0x0008,
// Low-word: color space definition
ImageFlagsColorSpaceRGB = 0x0010,
ImageFlagsColorSpaceCMYK = 0x0020,
ImageFlagsColorSpaceGRAY = 0x0040,
ImageFlagsColorSpaceYCBCR = 0x0080,
ImageFlagsColorSpaceYCCK = 0x0100,
// Low-word: image size info
ImageFlagsHasRealDPI = 0x1000,
ImageFlagsHasRealPixelSize = 0x2000,
// High-word
ImageFlagsReadOnly = 0x00010000,
ImageFlagsCaching = 0x00020000
};
enum RotateFlipType
{
RotateNoneFlipNone = 0,
Rotate90FlipNone = 1,
Rotate180FlipNone = 2,
Rotate270FlipNone = 3,
RotateNoneFlipX = 4,
Rotate90FlipX = 5,
Rotate180FlipX = 6,
Rotate270FlipX = 7,
RotateNoneFlipY = Rotate180FlipX,
Rotate90FlipY = Rotate270FlipX,
Rotate180FlipY = RotateNoneFlipX,
Rotate270FlipY = Rotate90FlipX,
RotateNoneFlipXY = Rotate180FlipNone,
Rotate90FlipXY = Rotate270FlipNone,
Rotate180FlipXY = RotateNoneFlipNone,
Rotate270FlipXY = Rotate90FlipNone
};
//---------------------------------------------------------------------------
// Image encoder parameter related types
//---------------------------------------------------------------------------
enum EncoderParameterValueType
{
EncoderParameterValueTypeByte = 1, // 8-bit unsigned int
EncoderParameterValueTypeASCII = 2, // 8-bit byte containing one 7-bit ASCII
// code. NULL terminated.
EncoderParameterValueTypeShort = 3, // 16-bit unsigned int
EncoderParameterValueTypeLong = 4, // 32-bit unsigned int
EncoderParameterValueTypeRational = 5, // Two Longs. The first Long is the
// numerator, the second Long expresses the
// denomintor.
EncoderParameterValueTypeLongRange = 6, // Two longs which specify a range of
// integer values. The first Long specifies
// the lower end and the second one
// specifies the higher end. All values
// are inclusive at both ends
EncoderParameterValueTypeUndefined = 7, // 8-bit byte that can take any value
// depending on field definition
EncoderParameterValueTypeRationalRange = 8, // Two Rationals. The first Rational
// specifies the lower end and the second
// specifies the higher end. All values
// are inclusive at both ends
'#if (GDIPVER >= 0x0110)
EncoderParameterValueTypePointer = 9 // a pointer to a parameter defined data.
'#endif //(GDIPVER >= 0x0110)
};
#define GDIPCONST
typedef struct {
dword d1
word w1,w2
byte b1,b2,b3,b4,b5,b6,b7,b8
} GUID,CLSID,*refiid
'
#define DEFINE_GUID(gu,d1,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) GUID gu<=(d1,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)
'======================
'Encoder parameter sets
'======================
DEFINE_GUID(EncoderCompression, 0xe09d739d,0xccd4,0x44ee,0x8e,0xba,0x3f,0xbf,0x8b,0xe4,0xfc,0x58);
DEFINE_GUID(EncoderColorDepth, 0x66087055,0xad66,0x4c7c,0x9a,0x18,0x38,0xa2,0x31,0x0b,0x83,0x37);
DEFINE_GUID(EncoderScanMethod, 0x3a4e2661,0x3109,0x4e56,0x85,0x36,0x42,0xc1,0x56,0xe7,0xdc,0xfa);
DEFINE_GUID(EncoderVersion, 0x24d18c76,0x814a,0x41a4,0xbf,0x53,0x1c,0x21,0x9c,0xcc,0xf7,0x97);
DEFINE_GUID(EncoderRenderMethod, 0x6d42c53a,0x229a,0x4825,0x8b,0xb7,0x5c,0x99,0xe2,0xb9,0xa8,0xb8);
DEFINE_GUID(EncoderQuality, 0x1d5be4b5,0xfa4a,0x452d,0x9c,0xdd,0x5d,0xb3,0x51,0x05,0xe7,0xeb);
DEFINE_GUID(EncoderTransformation,0x8d0eb2d1,0xa58e,0x4ea8,0xaa,0x14,0x10,0x80,0x74,0xb7,0xb6,0xf9);
DEFINE_GUID(EncoderLuminanceTable,0xedb33bce,0x0266,0x4a77,0xb9,0x04,0x27,0x21,0x60,0x99,0xe7,0x17);
DEFINE_GUID(EncoderChrominanceTable,0xf2e455dc,0x09b3,0x4316,0x82,0x60,0x67,0x6a,0xda,0x32,0x48,0x1c);
DEFINE_GUID(EncoderSaveFlag,0x292266fc,0xac40,0x47bf,0x8c, 0xfc, 0xa8, 0x5b, 0x89, 0xa6, 0x55, 0xde);
type EncoderParameter {
GUID guid
long NumberOfValues
long dwType
long value 'pointer to value block
}
type EncoderParameters {
UINT Count;
EncoderParameter Parameter[16]; 'pointers to EncoderParameter / arbitrary max count of 16
};
'=============================
'SELECECTED GDIPLUS PROCEDURES
'=============================
extern library "gdiplus.dll"
GpStatus WINGDIPAPI
GdiplusStartup( ULONG_PTR *token, GdiplusStartupInput *input, GdiplusStartupOutput *output);
void GdiplusShutdown(ULONG_PTR token);
GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc, GpGraphics **graphics);
GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream* stream, GpBitmap **bitmap);
GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(int width, height, stride, PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename, GpBitmap **bitmap);
GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream* stream, GpBitmap **bitmap);
GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR * filename, UINT access,
IStream **stream);
GpStatus WINGDIPAPI
GdipGetImageType(GpImage *image, ImageType *type);
GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage *image, UINT *width);
GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage *image, UINT *height);
GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage *image, UINT thumbWidth, UINT thumbHeight,
GpImage **thumbImage,
GetThumbnailImageAbort callback, VOID * callbackData);
GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y);
GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x, INT y);
GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics *graphics, GpImage *image, REAL x, REAL y, REAL width, REAL height);
GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics *graphics, GpImage *image, INT x, INT y, INT width, INT height);
GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage *image, RotateFlipType rfType);
GpStatus WINGDIPAPI
GdipDisposeImage(GpImage *image);
GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
GDIPCONST CLSID* clsidEncoder,
GDIPCONST EncoderParameters* encoderParams);
GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage *image, IStream* stream,
GDIPCONST CLSID* clsidEncoder,
GDIPCONST EncoderParameters* encoderParams);
GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics *graphics);
GpStatus WINGDIPAPI
GdipGetDC(GpGraphics* graphics, HDC * hdc);
GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics* graphics, HDC hdc);
GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR* filename, GpImage **image);
GpStatus WINGDIPAPI
GdipBitmapGetPixel( GpBitmap* bitmap, INT x, INT y, ARGB *color );
GpStatus WINGDIPAPI
GdipBitmapSetPixel( GpBitmap* bitmap, INT x, INT y, ARGB color );
GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, HBITMAP* hbmReturn, ARGB background);
'========================
'ImageCodecInfo structure
'========================
'itr const prefix
type ImageCodecInfo {
CLSID Clsid;
GUID FormatID;
WCHAR* CodecName;
WCHAR* DllName;
WCHAR* FormatDescription;
WCHAR* FilenameExtension;
WCHAR* MimeType;
DWORD Flags;
DWORD Version;
DWORD SigCount;
DWORD SigSize;
BYTE* SigPattern;
BYTE* SigMask;
}
GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT *numEncoders, UINT *size);
GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders,UINT size, ImageCodecInfo*Encoders);
typedef struct tagBITMAP {
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
} BITMAP, *PBITMAP;
long GdipCreateBitmapFromGraphics(sys Width, Height, Graphics, *pBitmap)
long GdipGetImageGraphicsContext(BITMAP *Bitmap, sys *Hdc)
long GdipGetDC(sys Graphics, *Hdc)
long GdipReleaseDC(sys Graphics, Hdc)
end extern 'gdiplus
function GDIplus(int mode) as sys
=================================
static sys hr,token
select mode
case 0 : if token then GdiplusShutdown token : token=0
case 2 : 'return token only
case 1 :
GdiplusStartupInput StartupInput
StartupInput.GdiplusVersion = 1
hr=GdiplusStartup Token, StartupInput, null
if hr then print "Error initializing GDIplus: " hex hr
end select
return token
end function
function GetEncoderClsid(string MimeType,GUID*clsid) as int
'==========================================================
'
'MIME TYPES
'image/bmp' 'image/jpeg' 'image/gif' 'image/tiff' 'image/png'
'
sys a,i,hr,numencoders,nsize
string ici
ImageCodecInfo* pImageCodecInfo
'
hr = GdipGetImageEncodersSize numEncoders, nSize
string buffer=nuls nSize
@pImageCodecInfo = strptr buffer
'
hr=GdipGetImageEncoders numEncoders, nSize, pImageCodecInfo
'
for i = 1 to numEncoders
ici=pImageCodecInfo.MimeType 'autoconvert to ascii string
a=instr 1,ici,MimeType
if a then
function=1 'success
copy @clsid, @pImageCodecInfo.Clsid, sizeof GUID
exit for
end if
@pImageCodecInfo+=sizeof ImageCodecInfo 'next info record
next
'
end function
sub SaveImage(string fname,typimg, int quality, LPVOID pBitMap)
'==============================================================
int hstatus
EncoderParameters eps
eps.Count=1
'
EncoderParameter*ep
@ep=@eps.parameter
ep.NumberOfValues=1
copy @ep.guid, @EncoderQuality,sizeof GUID
ep.dwtype=EncoderParameterValueTypeLong
ep.Value=@quality
GUID CodecId
GetEncoderClsid typimg, CodecId
'
'fname autoconvert
hstatus=GdipSaveImageToFile pBitMap, fname, codecId, eps
'
'print guidtxt codecId
end sub
function SaveClipBoardImage(sys hwnd=0, string fname="tim50.jpg", typimg="image/jpeg", int quality=50) as int
'============================================================================================================
'
'typimg: image/jpeg image/png image/gif image/tiff image/bmp
'quality: 1..100 percent
'
sys a,b,e,p
OpenClipBoard hwnd
a=GetClipboardData CF_BITMAP
b=GetClipboardData CF_PALETTE
e=GdipCreateBitmapFromHBITMAP a,b,p
if p then
SaveImage fname,typimg,quality,p
GdipDisposeImage p
function=1
end if
CloseClipBoard hwnd
end function
function SaveClientImage(sys hwnd,string fname="tim50.jpg", typimg="image/jpeg", int quality=50) as int
'======================================================================================================
'
'typimg: image/jpeg image/png image/gif image/tiff image/bmp
'quality: 1..100 percent
'
sys hstatus,hdcs,hdcm,width,height,hbitmap,mode
LPVOID pBitmap
RECT rect
'hdcs = GetWindowDC hWnd
'GetWindowRect hwnd, @rect
hdcs=GetDC hwnd
GetClientRect hwnd, @rect
width = rect.right - rect.left
height = rect.bottom - rect.top
hdcm = CreateCompatibleDC hdcs
hBitmap = CreateCompatibleBitmap hdcs, width, height
Selectobject hdcm,hbitmap
% CAPTUREBLT 0x40000000 ' Include layered windows
% SRCCOPY 0x00CC0020 ' dest = source
mode = SRCCOPY or CAPTUREBLT
BitBlt hdcm, 0, 0, width, height, hdcs, 0, 0, mode
hstatus=GdipCreateBitmapFromHBITMAP hBitmap,0,pBitMap
DeleteObject hbitmap
DeleteDC hdcm
ReleaseDC hwnd,hdcs
if pBitMap then
SaveImage fname,typimg,quality,pBitMap
GdipDisposeImage pBitMap
function=1
end if
end function
function TakePixelPhoto(sys hwnd,string fname,typimg, int quality, tr, any*pix, int wi, ht) as int
'=================================================================================================
'
'typimg: image/jpeg image/png image/gif image/tiff image/bmp
'quality: 1..100
'
int hstatus
sys pBitmap
int pf
int width = wi
int height = ht
% PixelFormat24bppRGB 137224
% PixelFormat32bppARGB 2498570
'http://forums.purebasic.com/english/viewtopic.php?p=205981
if tr
pf=PixelFormat32bppARGB
else
pf=PixelFormat24bppRGB
end if
sys a=@GdipCreateBitmapFromScan0
call a wi,ht,0,pf,0,@pBitmap
sys b,c,p,q,x,y
q=@pix
if tr
b=*q and 0xffffff 'assume uniform background
end if
for y=0 to <ht
for x=0 to <wi
c=*q
if tr
if b=(c and 0xffffff)
c and=0xffffff 'make pixel transparent
end if
end if
'RED BLUE SWAP
addr ecx,c
mov al,[rcx]
mov ah,[rcx+2]
mov [rcx],ah
mov [rcx+2],al
'
GdipBitmapSetPixel pBitMap,x,ht-y-1,c 'REVERSE Y
q+=4
next
next
if pBitMap then
SaveImage fname,typimg,quality,pBitMap
GdipDisposeImage pBitMap
function=1
end if
end function
'
function TakeSnapShot(sys hwnd,string fname="tim50.jpg", typimg="image/jpeg", int quality=50, tr=0, gl=0, wa=0) as int
'=====================================================================================================================
'
'itr problem with resize
'
'typimg: image/jpeg image/png image/gif image/tiff image/bmp
'quality: 1..100 percent
'tr tansparent backround (not jpeg)
'gl use opengl to read pixels from client area
'wa window area (0 client rect 1 window rect)
'
int hstatus,width,height,a
sys pBitmap,hDC
RECT r
if wa=1 then
GetWindowRect hwnd, @r
a=0
else
GetClientRect hwnd, @r
a=hWnd
end if
hDC=GetDC a
width = r.right - r.left
height = r.bottom - r.top
'http://www.jose.it-berater.org/gdiplus/reference/constants/gdipimagepixelformatconstants.htm
% PixelFormat24bppRGB 137224
% PixelFormat32bppARGB 2498570
'http://forums.purebasic.com/english/viewtopic.php?p=205981
'GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(int width, height, stride, pixelformat, BYTE* scan0, GpBitmap** bitmap)
sys b,c,e,p,q,x,y
#define GL_BGRA 0x80E1
p=getmemory width*height*4
if tr
if gl
#ifdef glReadPixels
glPixelStorei(GL_PACK_ALIGNMENT, 1)
glReadPixels 0,0,1,1,GL_BGRA,GL_UNSIGNED_BYTE,p
b=*p and 0xffffff 'assume uniform background
#endif
else
b=0xffffff and GetPixel hDC,1,1
end if
end if
if gl
#ifdef glReadPixels
glPixelStorei(GL_PACK_ALIGNMENT, 1)
glReadPixels 0,r.top,width,height,GL_BGRA,GL_UNSIGNED_BYTE,p
#endif
end if
int pf
pf=PixelFormat32bppARGB
if tr
q=0
else
q=p
endif
GdipCreateBitmapFromScan0(width,height,width*4,pf,byval q,pBitmap)
if tr=0
GdipImageRotateFlip(pBitmap, 6) 'Y flip
goto done
endif
'
for y=r.top to < r.bottom
q=p+y*width*4
for x=r.left to < r.right
if gl
c=*q
else
c=GetPixel hDC,x,y
end if
if tr
if b=(c and 0xffffff)
c and =0xffffff 'make pixel transparent
end if
end if
if gl
GdipBitmapSetPixel pBitMap,x,height-y-1,c 'REVERSE Y
q+=4
else
GdipBitmapSetPixel pBitMap,x,y,c
end if
next
next
'
done:
'
if pBitMap then
SaveImage fname,typimg,quality,pBitMap
GdipDisposeImage pBitMap
function=1
end if
ReleaseDC hDC
freememory p
end function
type Pixel4
dword color
=
byte r,g,b,a
end type
sub LoadPixImage(string name, sys size, string*pixels, optional int *owi,*oht, *pflip)
'=====================================================================================
'
typedef void *pvoid
'
int hstatus,wi,ht,flip
pvoid pImage
wstring wName
'
wName = name 'widestring
hStatus = GdipLoadImageFromFile wName, pImage
hStatus=GdipGetImageWidth pImage,wi
hStatus=GdipGetImageHeight pImage,ht
if @owi then owi=wi
if @oht then oht=ht
'
sys pb,w
int x,y,xe,ye
'
pb=pimage
'
/*
enum RotateFlipType
{
RotateNoneFlipNone = 0,
Rotate90FlipNone = 1,
Rotate180FlipNone = 2,
Rotate270FlipNone = 3,
RotateNoneFlipX = 4,
Rotate90FlipX = 5,
Rotate180FlipX = 6,
Rotate270FlipX = 7,
RotateNoneFlipY = Rotate180FlipX,
Rotate90FlipY = Rotate270FlipX,
Rotate180FlipY = RotateNoneFlipX,
Rotate270FlipY = Rotate90FlipX,
RotateNoneFlipXY = Rotate180FlipNone,
Rotate90FlipXY = Rotate270FlipNone,
Rotate180FlipXY = RotateNoneFlipNone,
Rotate270FlipXY = Rotate90FlipNone
};
*/
if @pflip then flip=pflip else flip=6
hStatus = GdipImageRotateFlip pb, flip ' 4 flipx 6 flipy
pixel4 pix
if size then
wi=size
ht=size
elseif wi then
else
wi=64 : ht=64
end if
pixels=nuls 4*wi*ht
xe=wi-1
ye=ht-1
w=strptr pixels
for y=0 to ye
for x=0 to xe
GdipBitmapGetPixel pb, x, y, pix.color
'swap pix.r, pix.b
#ifdef mode64bit
lea rcx,pix.color
mov rax,[rcx]
mov [rcx+2],al
shr rax,16
mov [rcx],al
#else
lea ecx,pix.color
mov eax,[ecx]
mov [ecx+2],al
shr eax,16
mov [ecx],al
#endif
*w=pix.color : w+=4
'GdipBitmapSetPixel pb, x, y, pix.color
next
next
'
'Cleanup
'
if pImage then GdipDisposeImage pImage
end sub
Nicola this is missing part in imgwin
def CF_BITMAP 2
def CF_PALETTE 9
Type RECT
Left as INT
Top as INT
Right as INT
Bottom as INT
End Type
% OFN_EXPLORER = 0x00080000
% OFN_FILEMUSTEXIST = 0x00001000
Hi Nicola,
I have adapted demos\Image\ImageWin2 for FileDialogs Opening 'O' and saving 'S'.
The only problem is to find a way of erasing the old image when a new one is loaded. The screen is not properly refreshed until you manually resize the window.
#case capital
def NULL null
uses MinWin
uses FileDialogs
uses ImgWin
'
'default image file setup
=========================
wstring strFileName = "../images/Dawn1815.jpg"
'
string filter="*.jpg"
string idir=""
string title="Load Image"
string name=""
sys hWnd=0
sys flags=0
sys saves=0
string ifile
'
'Function FileDialog(string iDir, filter, Title,Name, sys Hwnd, Flags,saves) As String
'ifile=FileDialog(idir,filter,title,name, hWnd,Flags,saves)
'
if ifile
strFileName=ifile
endif
#lookahead ' for procedures
'------------------------------
sub GetImages(sys hwnd,sys hdc)
'==============================
sys hstatus
sys pGraphics,pImage,pBitmap,pStream,pThumbnail
sys nThumbnailWidth,nThumbnailHeight,nwidth,nheight
'
hStatus = GdipCreateFromHDC hdc, pGraphics
'
' // Create an image and a thumbnail of the image.
'
hStatus = GdipLoadImageFromFile strFileName, 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 = GdipGetImageWidth pThumbnail, nThumbnailWidth
hStatus = GdipGetImageHeight pThumbnail, nThumbnailHeight
'
'
'DRAW IMAGES
'
hStatus = GdipDrawImageRect pGraphics, pThumbnail, 10, 10, nThumbnailWidth, nThumbnailHeight
hStatus = GdipDrawImageRectI pGraphics, pImage, 10, 60, nWidth, nHeight
'
'
'http://www.jose.it-berater.org/smfforum/index.php?topic=1860.0
'http://www.jose.it-berater.org/smfforum/index.php?topic=1861.0
' /jpeg /png /gif /tiff /bmp
'if pBitMap<>0 then SaveImage "tim50.jpg","image/jpeg",50,pBitMap 'itr trap param mismatch
'
' // Cleanup
'
if pThumbnail
GdipDisposeImage pThumbnail
endif
if pImage
GdipDisposeImage pImage
endif
if pBitMap
GdipDisposeImage pBitMap
endif
if pGraphics
GdipDeleteGraphics pGraphics
endif
'
end sub
'==================
'GLOBAL DEFINITIONS
'==================
sys inst,hdc
dim cmdline as asciiz ptr,inst as long
&cmdline=GetCommandLine
inst=GetModuleHandle 0
'--------------------------------------------------------------------------------------------------------------
Function WinMain(byval inst as long,byval prevInst as long,byval cmdline as asciiz, byval show as long) as long
'==============================================================================================================
sys hr,hdlg,token
GdiplusStartupInput StartupInput
StartupInput.GdiplusVersion = 1
hr=GdiplusStartup token, StartupInput, byval 0
'
if hr
print "Error initializing GDIplus: " hex hr
exit function
end if
WNDCLASS wc
MSG wm
sys hwnd, wwd, wht, wtx, wty, tax
wc.style = CS_HREDRAW or CS_VREDRAW
wc.lpfnWndProc = &WndProc
wc.cbClsExtra =0
wc.cbWndExtra =0
wc.hInstance =inst
wc.hIcon=LoadIcon 0, IDI_APPLICATION
wc.hCursor=LoadCursor 0,IDC_ARROW
wc.hbrBackground = GetStockObject WHITE_BRUSH
wc.lpszMenuName =0
wc.lpszClassName =@"Demo"
RegisterClass (&wc)
Wwd = 800 : Wht = 600
Tax = GetSystemMetrics SM_CXSCREEN
Wtx = (Tax - Wwd) /2
Tax = GetSystemMetrics SM_CYSCREEN
Wty = (Tax - Wht) /2
hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
ShowWindow hwnd,SW_SHOW
UpdateWindow hwnd
'
bool bRet
'
do while bRet := GetMessage (&wm, 0, 0, 0)
if bRet = -1
'show an error message
exit while
else
TranslateMessage &wm
DispatchMessage &wm
end if
wend
GdiplusShutdown token
End Function
RECT crect 'for WndProc and TimerProc
'--------------------------------------------------------------------------------------------------------------------------
function WndProc ( byval hWnd as long, byval wMsg as long, byval wParam as long, byval lparam as long ) as long callback
'==========================================================================================================================
static as Long count=0, refreshes=0, hdc
static as String txt
static as PAINTSTRUCT Paintst
'==========
select wMsg
'==========
'--------------
case WM_CREATE
'=============
'hTimer = SetTimer (hWnd, ID_TIMER, 100, &TimerProc)
GetClientRect hWnd,&cRect
'--------------
case WM_TIMER
'=============
'--------------
case WM_DESTROY
'===============
'KillTimer(hWnd,ID_TIMER)
PostQuitMessage 0
'------------
case WM_PAINT
'============
'TEXT
'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx
'DRAWING AND PAINTING
'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx
hDC=BeginPaint hWnd,&Paintst
'GetClientRect hWnd,&cRect
'DrawText hDC,"Hello",-1,&cRect,0x25
GetImages hWnd,hDC
'refreshes+=1
EndPaint hWnd,&Paintst
'ValidateRect hwnd,&crect
'-----------------
'case WM_ERASEBKGND
'=================
'RECT r
'GetClientRect hWnd,r
'GetImages hWnd,hDC
'InvalidateRect( hWnd,@r,0 )
'return 1
'--------------
case WM_KEYDOWN
'==============
'============
Select wParam
'============
Case 0x4f 'O Open
ifile=FileDialog(idir,filter,title,name, hWnd,Flags,0)
if iFile
StrFileName=iFile
GetClientRect hWnd,&cRect
InvalidateRect hWnd,&crect
endif
Case 0x53 'S Save
ifile=FileDialog(idir,filter,title,name, hWnd,Flags,1)
if iFile
SaveClientImage(hwnd,iFile)
endif
Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0 'ESCAPE
Case 80 ' P TO CAPTURE WINDOW IMAGE
'SaveClipBoardImage
SaveClientImage hwnd
End Select
'
'--------
case else
'========
function=DefWindowProc hWnd,wMsg,wParam,lParam
end select
end function ' WndProc
WinMain inst,0,cmdline,SW_NORMAL
Hi Charles
in the mentioned example ImageWin2.o2bas
this could be changed to avoid flickering when windows is resizing
wc.style = CS_DBLCLKS | CS_OWNDC 'CS_HREDRAW or CS_VREDRAW
Thanks Zlatko,
in fact the errors were related to what you rightly found missing.
However, it is strange that with imagewin1 and imagewin2 these errors do not occur, even though in fact in these two programs RECT is defined
Charles,
if I didn't want to use a gui, but just open and close in the background. Or maybe only via the command line?
You will need a window of some sort to display the image. But my simplest offering is to save a clipboard image:
#case capital
$filename "t.exe"
'uses rtl64
uses MinWin
uses ImgWin
GDIplus 1
SaveClipBoardImage
GDIplus 0
Charles,
How to use
GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename, GpBitmap **bitmap);
Do you have any examples?
in the file you attached, ImgWin2, there is this line that makes an example of it by SaveImage
'if pBitMap<>0 then SaveImage "tim50.jpg","image/jpeg",50,pBitMap 'itr trap param mismatch
To use the SaveImage function I need pBitMap
i found this
```cpp
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
int main ()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GpBitmap* bitmap = NULL;
WCHAR path[] = L"C:\\path\\to\\your\\image.jpg"; // Sostituisci con il percorso del tuo file immagine
// Inizializza GDI+
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// Crea un oggetto bitmap da un file
GdipCreateBitmapFromFile(path, &bitmap);
// Utilizza l'oggetto bitmap...
// Pulizia
if (bitmap) {
GdipDisposeImage(bitmap);
}
GdiplusShutdown(gdiplusToken);
return 0;
}
```
GDIplus is ancient, huge and complicated - like a dragon :) my encounters with it have been minimal.
This article might be a good starting point:
About cropping and scaling GDI+ images
https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-cropping-and-scaling-images-about
What do you want to do with your images?
As I said, open an image file (jpg, png, gif) see its size, reduce it if necessary and save while also changing the quality. All without opening a GUI.
Tried with the latest oxigenbasic.zip
#case capital
def NULL null
uses filedialogs
uses MinWin
uses ImgWin
#lookahead ' for procedures
'// var for fileopen
indexbase 1
string sep=chr(0)
string filter="jpg"+sep+"*.jpg"
sys tipogui = OFN_EXPLORER 'or OFN_ALLOWMULTISELECT
typedef void *pvoid
'
sys hstatus
sys pGraphics,pImage,pBitmap,pStream,pStreamo,pThumbnail
wstring strFileName
sys nThumbnailWidth,nThumbnailHeight,nwidth,nheight
'
'hStatus = GdipCreateFromHDC hdc, pGraphics
'
' // Create an image and a thumbnail of the image.
'
'strFileName = "../images/Dawn1815.jpg"
strFileName=FileDialog("C:\temp\1",filter,"Seleziona Immagine","", 0,tipogui,0)
'print strfilename
if strFileName ="" then
print "errore file"
ExitProcess(0)
endif
hStatus = GdipLoadImageFromFile strFileName, pImage
hStatus = GdipGetImageThumbnail pImage, 40, 40, pThumbnail, null, null
'GdipCreateBitmapFromFile(strFileName, LPVOID pBitMap)
GdipCreateBitmapFromFile(strFileName, *pBitMap)
if pBitMap=0 then
print "no pBitMap"
ExitProcess(0)
endif
'
' // Draw the original and the thumbnail images.
'
hStatus = GdipGetImageWidth pImage, nWidth
hStatus = GdipGetImageHeight pImage, nHeight
hStatus = GdipDrawImageRectI pGraphics, pImage, 10, 60, nWidth, nHeight
hStatus = GdipGetImageWidth pThumbnail, nThumbnailWidth
hStatus = GdipGetImageHeight pThumbnail, nThumbnailHeight
hStatus = GdipDrawImageRect pGraphics, pThumbnail, 10, 10, nThumbnailWidth, nThumbnailHeight
'SaveImage(string fname,typimg, int quality, LPVOID pBitMap)
SaveImage("c:\temp\1\o2.jpeg","image/jpeg", 50, pBitMap)
'
' // Cleanup
'
if pThumbnail
GdipDisposeImage pThumbnail
endif
if pImage
GdipDisposeImage pImage
endif
if pGraphics
GdipDeleteGraphics pGraphics
endif
if pBitMap
GdipDisposeImage pBitMap
endif
print "end"
QuoteAll without opening a GUI.
But Nicola that is in contradiction
GDI+ is good for let say simple image viewer i always want
to make in o2 but never make
Hi Zlatko.
That is true, but my desire is to do what I have described. Maybe then at a later time even do something else...
I already use Irfanview to manage the huge ones, but I wanted to try with O2 to change the quality, the size or whatever, but without necessarily using a GUI. I might want to do this for a large number of images, entire directories.
In addition to
inc\ImgWin.inc
We also have:
demos\!ProjB\GdiPlus\gdip.inc
(Peter Wirbelauer)
You can see how Images are loaded positioned and resized:
demos\!ProjB\GdiPlus\DevilGoHome.o2bas
demos\!ProjB\GdiPlus\Devil\Penguins.o2bas
QuoteAs I said, open an image file (jpg, png, gif) see its size, reduce it if necessary and save while also changing the quality
OK Nicola
...but as you said you need GUI window to see image which you loaded
normal way is to use FileDialog using filters .jpg .png .gif to open this types
of files ..images..
also usual way is to use child window inside main window to look into opened image
then you need some calculations to set raster images to size you want
i am not sure what they are or are even supported by GDIplus functions ..maybe yes
etc...etc...
I think that here on forum is one ImageViewer example by Jose Roca ..i am not
sure but i think that is here somewhere ..
I fixed it.
Now it's working fine. I'm ashamed to say, there was no GDI+ activation. In fact, I saw that hstatus gave me the value 18 which corresponds precisely to this eventuality.
Now the program allows me to open an image file and save it by lowering its quality.
I have to try to change the size as well.
#case capital
def NULL null
uses filedialogs
uses MinWin
uses ImgWin
#lookahead 'for procedures
'// var for fileopen
indexbase 1
string sep=chr(0)
string filter="jpg"+sep+"*.jpg"
sys tipogui = OFN_EXPLORER 'or OFN_ALLOWMULTISELECT
'//initiate the Gdip //
sys hr,hdlg,token
GdiplusStartupInput StartupInput
StartupInput.GdiplusVersion = 1
hr=GdiplusStartup token, StartupInput, byval 0
'
if hr
print "Error initializing GDIplus: " hex hr
terminate
end if
'//
typedef void *pvoid
'
sys hstatus
sys pGraphics,pImage,pBitmap,pStream,pStreamo,pThumbnail
wstring strFileName
sys nThumbnailWidth,nThumbnailHeight,nwidth,nheight
'
'hStatus = GdipCreateFromHDC hdc, pGraphics
'
' // Create an image and a thumbnail of the image.
'
'strFileName = "../images/Dawn1815.jpg"
strFileName=FileDialog("C:\temp\1",filter,"Seleziona Immagine","", 0,tipogui,0)
'print strfilename
if strFileName ="" then
print "errore file"
ExitProcess(0)
endif
hStatus = GdipLoadImageFromFile strFileName, pImage
if hStatus<>0 then print "GdipLoadImageFromFile " hStatus
hStatus = GdipGetImageThumbnail pImage, 40, 40, pThumbnail, null, null
'GdipCreateBitmapFromFile(strFileName, LPVOID pBitMap)
hStatus = GdipCreateBitmapFromFile(strFileName, *pBitMap)
if hStatus<>0 then print "GdipCreateBitmapFromFile " hStatus
if pBitMap=0 then
print "no pBitMap"
'ExitProcess(0)
endif
'
' // Draw the original and the thumbnail images.
'
hStatus = GdipGetImageWidth pImage, nWidth
hStatus = GdipGetImageHeight pImage, nHeight
hStatus = GdipDrawImageRectI pGraphics, pImage, 10, 60, nWidth, nHeight
hStatus = GdipGetImageWidth pThumbnail, nThumbnailWidth
hStatus = GdipGetImageHeight pThumbnail, nThumbnailHeight
hStatus = GdipDrawImageRect pGraphics, pThumbnail, 10, 10, nThumbnailWidth, nThumbnailHeight
'SaveImage(string fname,typimg, int quality, LPVOID pBitMap)
SaveImage("c:\temp\1\o2.jpg","image/jpeg",1, pBitMap)
'
' // Cleanup
'
if pThumbnail
GdipDisposeImage pThumbnail
endif
if pImage
GdipDisposeImage pImage
endif
if pGraphics
GdipDeleteGraphics pGraphics
endif
if pBitMap
GdipDisposeImage pBitMap
endif
GdiplusShutdown token
int ids=ShellExecute(0,"open", "c:\temp\1\o2.jpg", "", "",1)
print "end"
Hi Nicola, Well done!
This is what I have, with size setting. It may not be a limitation for you but the quality seems to be automatically restricted for thumbnails.
'SaveThumbnail.o2bas / demo
#case capital
uses MinWin
uses ImgWin
'========================================
function SaveThumbnail(
sys pImage=0,
string fname="thumbnail.jpg",
typimg="image/jpeg",
int quality=50,
width=100, height=100 ) as int
'========================================
'
'typimg: image/jpeg image/png image/gif image/tiff image/bmp
'quality: 1..100
'
int hstatus
sys pThumbnail 'pimage for thumbnail
% PixelFormat24bppRGB 137224
% PixelFormat32bppARGB 2498570
'http://forums.purebasic.com/english/viewtopic.php?p=205981
if pImage
'hStatus = GdipGetImageThumbnail pImage, 40, 40, pThumbnail, NULL, NULL
hStatus = GdipGetImageThumbnail pImage, width, height, pThumbnail, 0, 0
SaveImage fname,typimg,quality,pThumbnail
GdipDisposeImage pThumbnail
function=1
endif
end function
#case capital
uses MinWin
uses ImgWin
GDIplus 1
sys pImage
wstring file="../images/Dawn1815.jpg"
GdipLoadImageFromFile(file,pimage)
SaveThumbnail(pimage,quality=50,width=100,height=100) 'defaults
GdipDisposeImage pImage
GDIplus 0
Hi Charles,
In fact, last night I started looking at the various functions available and I found the same way that you are telling me.
Through thumbnails you can obtain and reduce the image as you wish. In the example I post, I take the size of the initial image and in the thumbnail I divide it in half and save the thumbnail with the desired quality.
At the same time, I tried another system. If you see there's a do... Loop. Through this loop I control the reduced image file size and reduce its quality until the file size reaches the value I want.
The whole thing works very well. I had to insert two functions, FILEEXISTS and FILELN.
Also I tried save without using pBitMap, but using pImage, it works the same with the same result.
I am very satisfied with what we have been able to do.
'Open and Save
'usa GDI+
'Adattamento di Nicola Piano
'08/03/2024
'============================
#case capital
def NULL null
uses filedialogs
uses MinWin
uses ImgWin
#lookahead 'for procedures
function FileExists(char*fi) as int
===================================
WIN32_FIND_DATA fd
sys h
h=FindFirstFile fi,fd
if h>0 then
FindClose h
return 1
end if
end function
function Fileln(char*fi) as int
===============================
sys f
int le
if FileExists(fi)<>1 then return 0
f=fopen fi,"r"
if f
int n=_fileno f
le = _filelength n
'print le
fclose f
return le
end if
end function
'// var for fileopen
indexbase 1
string sep=chr(0)
string filter="jpg"+sep+"*.jpg"
sys tipogui = OFN_EXPLORER 'or OFN_ALLOWMULTISELECT
'//initiate the Gdip //
sys hr,hdlg,token
GdiplusStartupInput StartupInput
StartupInput.GdiplusVersion = 1
hr=GdiplusStartup token, StartupInput, byval 0
'
if hr
print "Error initializing GDIplus: " hex hr
terminate
end if
'//
typedef void *pvoid
'
sys hstatus
sys pGraphics,pImage,pBitmap,pStream,pStreamo,pThumbnail
wstring strFileName
sys nThumbnailWidth,nThumbnailHeight,nwidth,nheight
'
'hStatus = GdipCreateFromHDC hdc, pGraphics
'
' // Create an image and a thumbnail of the image.
'
'strFileName = "../images/Dawn1815.jpg"
strFileName=FileDialog("C:\temp\1",filter,"Seleziona Immagine","", 0,tipogui,0)
'print strfilename
if strFileName ="" then
print "errore file"
ExitProcess(0)
endif
hStatus = GdipLoadImageFromFile strFileName, pImage
if hStatus<>0 then print "GdipLoadImageFromFile " hStatus
hStatus = GdipGetImageWidth pImage, nWidth
hStatus = GdipGetImageHeight pImage, nHeight
'hStatus = GdipGetImageThumbnail pImage, 40, 40, pThumbnail, null, null
hStatus = GdipGetImageThumbnail pImage, nWidth/2, nHeight/2, pThumbnail, null, null
'GdipCreateBitmapFromFile(strFileName, LPVOID pBitMap)
hStatus = GdipCreateBitmapFromFile(strFileName, *pBitMap)
if hStatus<>0 then print "GdipCreateBitmapFromFile " hStatus
if pBitMap=0 then
print "no pBitMap"
'ExitProcess(0)
endif
'
' // Draw the original and the thumbnail images.
'
hStatus = GdipDrawImageRectI pGraphics, pImage, 10, 60, nWidth, nHeight
hStatus = GdipGetImageWidth pThumbnail, nThumbnailWidth
hStatus = GdipGetImageHeight pThumbnail, nThumbnailHeight
hStatus = GdipDrawImageRect pGraphics, pThumbnail, 10, 10, nThumbnailWidth, nThumbnailHeight
wstring outFname="c:\temp\1\o2.jpg"
int qualita=20, dimage=100000
'riduce la qualità fino a che la dimensione del file è quello desiderato.
do
qualita-=1
'SaveImage(string fname,typimg, int quality, LPVOID pBitMap)
SaveImage(outFname,"image/jpeg",qualita, pBitMap)
'SaveImage("c:\temp\1\o2_.jpg","image/jpeg",1, pImage)
loop until Fileln(outFname)<=dimage
SaveImage("c:\temp\1\o2_half.jpg","image/jpeg",20, pThumbnail) 'funziona
'
' // Cleanup
'
if pThumbnail
GdipDisposeImage pThumbnail
endif
if pImage
GdipDisposeImage pImage
endif
if pGraphics
GdipDeleteGraphics pGraphics
endif
if pBitMap
GdipDisposeImage pBitMap
endif
GdiplusShutdown token
int ids=ShellExecute(0,"open", "c:\temp\1\o2.jpg", "", "",1)
print "end"