QB64Team / qb64

BASIC for the modern era.

Home Page:https://www.qb64.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

_PUTIMAGE option adjust image but maintain 1:1 aspect ratio

richardFK opened this issue · comments

Currently

If the area of the source is bigger or smaller than the area of the
destination then the image is adjusted to fit that area.

However the aspect ratio is not preserved.

Feature request - option to adjust image to fit the destination but also maintain 1:1 aspect ratio.

commented

Like a streamlined way of doing _PutImage (DestX1, DestY1)-(DestX2, DestY2), source, dest, (0, 0)-Step(_Width(source), _Height(source))?

Like a streamlined way of doing _PutImage (DestX1, DestY1)-(DestX2, DestY2), source, dest, (0, 0)-Step(_Width(source), _Height(source))?

I see no difference visually when using your code example and this from the Wiki:
_PUTIMAGE , sourceHandle&, destHandle& 'size full source to fit full destination area

commented

Oh, my bad! I thought you wanted to crop the image.

To simply put the full image to a portion of the destination keeping a 1:1 aspect, you use _PutImage (destx, desty)-Step(_Width(source), _Height(Source)), source, dest

@richardFK Please advise if the above code snippets are what you are hoping to achieve.

Below is relevant code (written about a year ago - not looked at since) which I wanted to "improve upon" - in this case it would place a "rectangle image" (tall or wide) into a "square destination". The whole image is displayed (no cropping) and 1:1 aspect ratio is kept.

As my computer just "froze up to have only a black screen" (and could not recover) - I will have to spend a number of hours sorting out what I can manually recover from a continuous 3-day run. It may have nothing to do with QB64 - but ever since I started using QB64 v1.5 stable release, I always get a black screen after say a 1-2 day continuous run of my QB64 programs (of course my bet is it is a Windows 10 problem!)

        pic% = 256            ' size of square destination
        h& = _LOADIMAGE(img$)
        ymax! = _HEIGHT(h&)
        xmax! = _WIDTH(h&)
        
        IF xmax! > ymax! THEN
            x1% = x0% + pic%: y1% = y0% + pic% * (ymax! / xmax!)
        ELSE
            x1% = x0% + pic% * (xmax! / ymax!): y1% = y0% + pic%
        END IF
    
    _PUTIMAGE (x0%, y0%)-(x1%, y1%), img& 

and off course elsewhere in program h& handle check and _FREEIMAGE

Hopefully get back to you in 2 days time.

As my computer just "froze up to have only a black screen" (and could not recover) - I will have to spend a number of hours sorting out what I can manually recover from a continuous 3-day run. It may have nothing to do with QB64 - but ever since I started using QB64 v1.5 stable release, I always get a black screen after say a 1-2 day continuous run of my QB64 programs (of course my bet is it is a Windows 10 problem!)

I'm willing to bet that it is more likely a problem with your code causing too much memory usage due to a leak or an ever-increasing string. I would recommend that you go through your code. I would also recommend that you either join our Discord server or the forum and ask questions there. There are many users and you will be able to receive help quickly.

This seems like it'd be better served by a user-defined function. Closing for now (#wontfix).