Quantcast
Channel: SCN: Message List - PowerBuilder Developer Center
Viewing all articles
Browse latest Browse all 7329

Re: Freeimage from PB Classic

$
0
0

I used it to open a BMP, crop it and save it like JPG

 

in the local External Functions....

// FreeImage Library

Function long FreeImage_SaveU(long fif, long dib, string filename, int flags) library "FreeImage.dll" alias for "_FreeImage_SaveU@16"

Function long FreeImage_LoadU(long fif, string filename, long flags) Library "FreeImage.dll" Alias for "_FreeImage_LoadU@12"

Subroutine FreeImage_Unload(long dib) Library "FreeImage.dll" Alias for "_FreeImage_Unload@4"

Subroutine FreeImage_Initialise(long load_local_plugins_only) Library "FreeImage.dll" Alias for "_FreeImage_Initialise@4"

Function long FreeImage_ConvertTo24Bits(long dib) Library "FreeImage.dll" Alias for "_FreeImage_ConvertTo24Bits@4"

function long FreeImage_Copy(long dib, int left, int top, int right, int bottom) library "FreeImage.dll" alias for "_FreeImage_Copy@20"

 

in the Instance Variables:

// FreeImage Library

Constant long JPEG_DEFAULT = 0

Constant long JPEG_FAST = 1

Constant long JPEG_ACCURATE = 2

Constant long JPEG_QUALITYSUPERB = 128 //&H80

Constant long JPEG_QUALITYGOOD = 256 //&H100

Constant long JPEG_QUALITYNORMAL = 512 //&H200

Constant long JPEG_QUALITYAVERAGE = 1024 //&H400

Constant long JPEG_QUALITYBAD = 2048 // &H800

Constant long JPEG_CMYK = 4096 //&H1000

 

 

constant long FIF_UNKNOWN = -1

constant long FIF_BMP = 0

constant long FIF_ICO = 1

constant long FIF_JPEG = 2

constant long FIF_JNG = 3

constant long FIF_KOALA = 4

constant long FIF_LBM = 5

constant long FIF_IFF = FIF_LBM

constant long FIF_MNG = 6

constant long FIF_PBM = 7

constant long FIF_PBMRAW = 8

constant long FIF_PCD = 9

constant long FIF_PCX = 10

constant long FIF_PGM = 11

constant long FIF_PGMRAW = 12

constant long FIF_PNG = 13

constant long FIF_PPM = 14

constant long FIF_PPMRAW = 15

constant long FIF_RAS = 16

constant long FIF_TARGA = 17

constant long FIF_TIFF = 18

constant long FIF_WBMP = 19

constant long FIF_PSD = 20

constant long FIF_CUT = 21

constant long FIF_XBM = 22

constant long FIF_XPM = 23

constant long FIF_DDS = 24

constant long FIF_GIF     = 25

constant long FIF_HDR = 26

constant long FIF_FAXG3 = 27

constant long FIF_SGI = 28

constant long FIF_EXR = 29

constant long FIF_J2K = 30

constant long FIF_JP2 = 31

constant long FIF_PFM = 32

constant long FIF_PICT = 33

constant long FIF_RAW = 34

constant long FIF_WEBP = 35

constant long FIF_JXR = 36

 

 

Example to open a BMP, crop it and save as JPG

// load BMP

ll_bitmap = FreeImage_LoadU(FIF_BMP, ls_BMPfile, 0)

if ll_bitmap <= 0 then return 'error loading temp bmp'

 

 

// Calculate crop size

ll_Height = il_alto * il_porcentaje / 100

ll_Width = ll_AltoRecorte / 1.3

ll_X = (il_ancho - ll_AnchoRecorte) / 2

ll_Y = (il_alto - ll_AltoRecorte) / 2

 

 

// take the crop

ll_bitmap2 = freeimage_copy(ll_bitmap, ll_X, ll_Y, ll_X + ll_Width, ll_Y + ll_Height)

 

 

// Converts to 24bits to save in JPG

ll_bitmap3 = FreeImage_ConvertTo24Bits(ll_bitmap2)

 

 

// save JPG

ll_rtn = FreeImage_SaveU( 2, ll_bitmap3, ls_JPGfile, JPEG_QUALITYSUPERB)

if ll_rtn <= 0 then return 'error saving'

 

 

// free up memory

FreeImage_Unload(ll_bitmap)

FreeImage_Unload(ll_bitmap2)

FreeImage_Unload(ll_bitmap3)


Viewing all articles
Browse latest Browse all 7329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>