FBImage static Win/Lin 32/64-bit

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: FBImage static Win/Lin 32/64-bit

Postby Roland Chastain » May 05, 2018 20:08

@Joshy

How can I get a (rectangle) part of an image? The image is loaded with LoadRGBAFile().

Thank you.
D.J.Peters
Posts: 7478
Joined: May 28, 2005 3:28

Re: FBImage static Win/Lin 32/64-bit

Postby D.J.Peters » May 05, 2018 21:05

Roland Chastain wrote:How can I get a (rectangle) part of an image? The image is loaded with LoadRGBAFile().
Same as before with the GET command :-)
https://www.freebasic.net/wiki/wikka.ph ... etgraphics

e.g.
var LoadedImage = LoadRGBAFile("blabla.bla")
var NewImage = ImageCreate(100,100)
Get LoadedImage, (x,y) - STEP(99,99), NewImage

NOTE: !!! STEP(99,99) not STEP(100,100) !!!
Ask if you run in to trouble.

Joshy
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: FBImage static Win/Lin 32/64-bit

Postby Roland Chastain » May 05, 2018 21:44

@Joshy

Perfect, thank you.
D.J.Peters
Posts: 7478
Joined: May 28, 2005 3:28

Re: FBImage static Win/Lin 32/64-bit

Postby D.J.Peters » May 05, 2018 22:06

For advanced use I created PutResize
you can cut a part of Image or Screen
optional scale it and put the result to Image or Screen
viewtopic.php?f=7&t=26672

MultiPut V2 optional scale and rotate Image and put the result on Screen or Image
viewtopic.php?f=7&t=24479&p=220305

Draw perspective correct Image as polygon 2D/3D
viewtopic.php?f=7&t=26090

Of course you can combine them.
Load an Image with FBImage
get a part of the loaded image with PutResize (optional scale it down or up)
put it rotated on the Screen or Image with Multiput V2
...

Joshy
leopardpm
Posts: 1642
Joined: Feb 28, 2009 20:58

Re: FBImage static Win/Lin 32/64-bit

Postby leopardpm » Dec 05, 2018 17:58

Joshy,

In your code here:

Code: Select all

#include once "FBImage.bi"

' load RGBA png (with alpha channel)

chdir exepath()

screenres 640,480,32 ' RGBA

line (0,0)-step(639,479),&HFF0000FF,BF

var img = LoadRGBAFile("lights_alpha.png")

put (0,0),img,ALPHA

sleep
ImageDestroy img


I need the img variable to be 'shared'... but it doesn't work when I change it to:

Code: Select all

var shared img = LoadRGBAFile("lights_alpha.png")


what am I doing wrong?

Here is the error output (also, am I using the latest FBC?)
Compiler output:
C:\blahblahblah\FBIDETEMP.bas(13) error 11: Expected constant in 'var shared img = LoadRGBAFile("lights_alpha.png".png")'

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for win32 (32bit)
OS: Windows NT 6.2 (build 9200)
badidea
Posts: 1050
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FBImage static Win/Lin 32/64-bit

Postby badidea » Dec 05, 2018 18:55

leopardpm wrote:...

Expected constant in 'var shared img = LoadRGBAFile("lights_alpha.png".png")'
....................................................!................!....!
leopardpm
Posts: 1642
Joined: Feb 28, 2009 20:58

Re: FBImage static Win/Lin 32/64-bit

Postby leopardpm » Dec 05, 2018 20:59

if you are pointing out the extra paranthesis... that was just a copy paste error into the forum... this gives same error:

Compiler output:
C:\FBIDETEMP.bas(13) error 11: Expected constant in 'var shared img = LoadRGBAFile("lights_alpha.png")'
Imortis
Posts: 1582
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: FBImage static Win/Lin 32/64-bit

Postby Imortis » Dec 05, 2018 21:18

leopardpm wrote:what am I doing wrong?


https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgShared
Shared variables can only be initialized with static values. You need to break it into two lines, meaning you can't use var here. You will need to use Dim.
dodicat
Posts: 5319
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FBImage static Win/Lin 32/64-bit

Postby dodicat » Dec 05, 2018 21:20

You have to create img, then set it to a value in the next line.

I don't know what LoadRGBAFile("lights_alpha.png")' returns (any ptr , fbimage, ...)


Code: Select all

 
declare function load(s as string) as any ptr

dim shared as typeof(load("")) image   'or if you know the typeof put it in.
image=load("something")


function load(s as string) as any ptr
    return imagecreate(200,200)
end function
 
dodicat
Posts: 5319
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FBImage static Win/Lin 32/64-bit

Postby dodicat » Dec 05, 2018 21:22

sorry Imortis, I missed your reply.
leopardpm
Posts: 1642
Joined: Feb 28, 2009 20:58

Re: FBImage static Win/Lin 32/64-bit

Postby leopardpm » Dec 05, 2018 21:35

so, this works... but is it the correct way to use FBimage to load an image? should I be using 'any ptr' as the variable type or something else?

Code: Select all

dim shared as any ptr img
img = LoadRGBAFile("lights_alpha.png")
leopardpm
Posts: 1642
Joined: Feb 28, 2009 20:58

Re: FBImage static Win/Lin 32/64-bit

Postby leopardpm » Dec 05, 2018 21:36

Thanks for your help, BTW!
dodicat
Posts: 5319
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FBImage static Win/Lin 32/64-bit

Postby dodicat » Dec 05, 2018 22:12

I just checked, any ptr is the type.
leopardpm
Posts: 1642
Joined: Feb 28, 2009 20:58

Re: FBImage static Win/Lin 32/64-bit

Postby leopardpm » Dec 05, 2018 22:26

good

also... I usually take extended breaks from programming and forget how to use things...like libraries. I want to make sure I am doing it correctly:

I put the FBimage.bi file into my 'inc' folder in the Freebasic folder
C:\Program Files (x86)\FreeBASIC\inc


and I put the two weird files:
libFBImage-32-static.a
libFBImage-64-static.a

into the 'win32' folder which is in the 'lib' folder:
C:\Program Files (x86)\FreeBASIC\lib\win32


couldn't find help on using libraries... figured there would be a sticky in the library section, but alas, no luck there either

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests