Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: vonskie on September 13, 2017, 04:55:48 pm

Title: Why does this Seg fault? bgrareplace
Post by: vonskie on September 13, 2017, 04:55:48 pm
Why does this Seg fault here


>>>>bgrareplace(bmp,newimage);
       
Here is the code

Am I using bgrareplace correctly?


bmp := TBGRABitmap.Create;
        bmp.LoadFromfile(imageselected.Text);

        try
        newimage := TBGRABitmap.Create(screen.Width, screen.Height, BGRABlack);
        newimage.PutImage(0, 0, bmp, dmDrawWithTransparency);
        bgrareplace(bmp,newimage);
        finally
        newimage.free;
        end;

        bmp.SaveToFile(filepath + 'wallpaper.bmp');
        bmp.free;

Title: Re: Why does this Seg fault? bgrareplace
Post by: lainz on September 15, 2017, 07:37:19 pm
You can upload a small program that reproduces the error?
Title: Re: Why does this Seg fault? bgrareplace
Post by: vonskie on September 15, 2017, 11:50:43 pm
i think bgrareplace automatically frees newimage so the finally newimage.free was an issue.

Title: Re: Why does this Seg fault? bgrareplace
Post by: lainz on September 16, 2017, 12:38:38 am
i think bgrareplace automatically frees newimage so the finally newimage.free was an issue.

BGRAReplace is designed to replace the same image, like

BGRAReplace(bmp, bmp.Resample(...) as TBGRABitmap);

Because some methods creates a new bitmap, usually you want to be the same bitmap as output, like when you do, for example, resample, blur and other filters.
Title: Re: Why does this Seg fault? bgrareplace
Post by: circular on September 17, 2017, 07:10:43 pm
Indeed. BGRAReplace frees the destination image.
TinyPortal © 2005-2018