FBImage static Win/Lin 32/64-bit

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Roland Chastain
Posts: 1008
Joined: Nov 24, 2011 19:49
Location: France
Contact:

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

Post by Roland Chastain »

@Joshy

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

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

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

Post by D.J.Peters »

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: 1008
Joined: Nov 24, 2011 19:49
Location: France
Contact:

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

Post by Roland Chastain »

@Joshy

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

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

Post by D.J.Peters »

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: 1795
Joined: Feb 28, 2009 20:58

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

Post by leopardpm »

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: 2594
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Post by badidea »

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

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

Post by leopardpm »

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
Moderator
Posts: 1929
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

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

Post by Imortis »

leopardpm wrote:what am I doing wrong?
https://www.freebasic.net/wiki/wikka.ph ... eyPgShared
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: 7995
Joined: Jan 10, 2006 20:30
Location: Scotland

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

Post by dodicat »

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: 7995
Joined: Jan 10, 2006 20:30
Location: Scotland

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

Post by dodicat »

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

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

Post by leopardpm »

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: 1795
Joined: Feb 28, 2009 20:58

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

Post by leopardpm »

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

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

Post by dodicat »

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

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

Post by leopardpm »

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
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

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

Post by Landeel »

I had to make a small change in the header to compile with fbc 1.08.0.

Just changed

Code: Select all

imageinfo imgDst,,,,dpitch,d
to

Code: Select all

dim as integer w2,h2
imageinfo imgDst,w2,h2,,dpitch,d 
This is very useful BTW.
Thank you again, D.J.Peters.
Post Reply