#include "a2d.hsp"
#module a2d_mod_jpg
#define global alSaveFileJpeg(%1, %2=100, %3=0, %4=0,%5=imgWidth@a2d, %6=imgHeight@a2d) alSaveFileJpeg_ %1, %2, %3, %4, %5, %6
#deffunc alSaveFileJpeg_ str p1, int quality, int px, int py, int pw, int ph ; filename, quality, rect
if ( CLSID == 0) {
CLSID = 0x557CF401, 0x11D31A04, 0x0000739A, 0x2EF31EF8 // JPEG
dim EncoderParameter, 8
EncoderParameter(0) = 1
EncoderParameter(1) = 0x1D5BE4B5, 0x452DFA4A, 0xB35DDD9C, 0xEBE70551 // CLSID_QUALITY
EncoderParameter(5) = 1
EncoderParameter(6) = 4
EncoderParameter(7) = varptr(q)
}
q = quality
if( q < 1 ) {
q = 80
}
GdipCreateBitmapFromScan0@a2d pw, ph, 0, PixelFormat32bppARGB@a2d, 0, varptr(tmpImage)
GdipGetImageGraphicsContext@a2d tmpImage, varptr(tmpGraphics)
GdipDrawImageI@a2d tmpGraphics, imgImage@a2d, -px, -py
GdipSaveImageToFile@a2d tmpImage, p1, varptr(CLSID), varptr(EncoderParameter)
GdipDeleteGraphics@a2d tmpGraphics
tmpGraphics = 0
GdipDisposeImage@a2d tmpImage
tmpImage = 0
return 0
#global
// --- 以下サンプル
strInput = dir_exe + "\\sample\\hspcv\\bgsamp.jpg"
strOutput = dir_desktop + "\\hsp3test.jpg"
alCreateImageByFile 0, strInput
exec strInput, 16
alSaveFileJpeg strOutput, 1
exec strOutput, 16