Been looking for FreeBASIC code to load .jpg images which I seem to remember exists somewhere but haven't been able to locate it?
Tried this but failed to compile.
viewtopic.php?t=15284&highlight=jpeg+function
Command executed:
"C:\FreeBasic\fbc.exe" "C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas"
Compiler output:
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(490) error 57: Type mismatch, at parameter 2 (aData) of DECODE_BLOCK() in 'if decode_block(z, aData(0), _'
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(498) error 57: Type mismatch, at parameter 3 (aData) of IDCT_BLOCK() in 'aData(0), _'
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(526) error 57: Type mismatch, at parameter 2 (aData) of DECODE_BLOCK() in 'if decode_block(z, aData(0), _'
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(535) error 57: Type mismatch, at parameter 3 (aData) of IDCT_BLOCK() in 'z->img_comp(n).w2, aData(0), @z->dequant(z->img_comp(n).tq))'
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)
How to load a .jpg file [SOLVED]
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
How to load a .jpg file [SOLVED]
Last edited by BasicCoder2 on Nov 01, 2018 6:24, edited 1 time in total.
Re: How to load a .jpg file
You need to change aData(0) to aData() in 4 places (each of the errors) and it will work.
I just tried it.
I just tried it.
Re: How to load a .jpg file
Yes:
changelog.txt wrote: Version 1.00.0 (former 0.91.0):
[fixed]
- #576: Array elements could be passed to array parameters in place of the array itself: <myfunction( myarray(index) )>. However, the array index was simply ignored. The array must be passed without index now: <myfunction( myarray() )>
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: How to load a .jpg file [SOLVED]
Thanks it works now. I wanted to automatically convert a stack of .jpg images taken from a video to .bmp images.
Also am using Joshy's imageScale(image,ratio) function.
Now I don't have to do it all manually with PAINT as I had done up to now !!
The images were extracted using this software because I suspect there is no FreeBASIC function to do that?
https://www.dvdvideosoft.com/guides/fre ... verter.htm
Also am using Joshy's imageScale(image,ratio) function.
Now I don't have to do it all manually with PAINT as I had done up to now !!
The images were extracted using this software because I suspect there is no FreeBASIC function to do that?
https://www.dvdvideosoft.com/guides/fre ... verter.htm
Code: Select all
....
'===========================================================================
' simple test
dim as integer w,h,BytesPerPixel
dim as ubyte ptr pImageBuffer
pImageBuffer=LoadJPG("testImage.jpg",w,h,BytesPerPixel)
screenres 640,480,32
dim shared as any ptr myImage
myImage = imagecreate(1280,720)
if pImageBuffer then
'screenres w,h,BytesPerPixel*8
dim as ubyte ptr pRGB=pImageBuffer
'screenlock
for y as integer=0 to h-1
for x as integer=0 to w-1
pset myImage,(x,y),rgb(pRGB[0],pRGB[1],pRGB[2])
pRGB+=BytesPerPixel
next
next
screenlock
put (0,0),ImageScale(myImage,.20),trans
'put (0,0),myImage,trans
screenunlock
if pImageBuffer then deallocate(pImageBuffer)
end if
sleep
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: How to load a .jpg file [SOLVED]
For what it's worth, you can extract the frames directly to bmp using ffmpeg (or avconv):
Credit: https://superuser.com/questions/391257/ ... -or-ffmpeg
Code: Select all
ffmpeg -i input.mp4 -vf "select=not(mod(n\,10))" -vsync vfr output_%03d.bmp
Re: How to load a .jpg file [SOLVED]
On linux, via CLI, I use ImageMagick for batch image conversion.
Re: How to load a .jpg file [SOLVED]
If you don't care about Linux compatibility you can use the Windows built-in library GDIPlus to load / save images in several formats, such as JPG, PNG, BMP, GIF, TIFF.
Check this out: LoadImage / SaveImage
Check this out: LoadImage / SaveImage