leapmotion / FreeImage

Modifications to build FreeImage for the Leap Motion environment
Other
4 stars 7 forks source link

FreeImage_Paste () fails whatever I try, please help me #1

Open gaamaaresosa opened 5 months ago

gaamaaresosa commented 5 months ago

I use VB6 wrapper module for years successfully.

Today I need to load a PNG file and copy some portion from that and paste it on another new dib and save a new PNG file. Until copy no issues I get a valid image on new dibSplit. But to paste that result on another new dib, I don't know what to do.

1) First of all there is no function seen in FreeImage VB6 wrapper to create an empty dib with a specified dimension. 2) So I tried loading another PNG image and created new dibDst. 3) FreeImage_Paste always return false.

Here is my code:

'Loading 1st image
Dim FIF As FREE_IMAGE_FORMAT
FIF = FreeImage_GetFileType(FileName)
dib = FreeImage_Load(FIF, FileName, FILO_PNG_DEFAULT)

'Creating a new dib to paste.
dibDst = FreeImage_Load(FIF, FileName, FILO_PNG_DEFAULT)
dibDst = FreeImage_Rescale(dibDst, MediaThumbWidth, MediaThumbHeight, FILTER_BICUBIC)

'Creating new splited and copying (A portion from 1st image) 
dibSplit = FreeImage_Copy(dib, 0, 0, 100, 100)
'Its is success !

'Now whated to paste it on a new dibDst.
Res = FreeImage_Paste(dibDst, dibSplit, 0, 0, 255)
Res is always False !

Last 2 days I have no success ! If I do it on GDI+ API, then it will take me more days. Please help me !!!

Thanks in advance.

gaamaaresosa commented 5 months ago

My problem is solved. After 2 days of experiment, I couldn't find the clue at all. But the below link helped me. 1) FreeImage_Allocate() with proper dimension succeeded the FreeImage_Paste()

(Carsten Klein - 2009-02-20) https://sourceforge.net/p/freeimage/discussion/36110/thread/b2bd58bc/

Attention: Currently, the image pasted with FreeImage_Paste must not exceed any of the destination image's sides. There is no automatic clipping performed so, you have to ensure that parameters top and left are not smaller than 0 (zero) and left + as well as top + are not greater than the width or height of the destination image respectively.