Reading a JPG image ...
Blitz3D Forums/Blitz3D Programming/Reading a JPG image ...
| ||
... that is *not* in a JPG file. Say I have a JPG picture data in a bank, but I dont have the .jpg file (data received by network stream, generated ...). How can I read that data to view the picture ? The only solution I can think of right now is writing that data as a file then reading the file with loadimage or some other function. However, as the tool im working on is supposed to read lots of images, think the writefile/loadimage method might not be the best thing. I did a quick search for jpeg reading dlls but cound only find dll asking for a file name and not directly data. Any idea ? |
| ||
Maybe you can use the FreeImage.dll ? I've never used it, but here is a topic with .decls for it. http://www.blitzbasic.com/Community/posts.php?topic=48558 There is a command that is called FIFromBank, which sounds promising.. |
| ||
if it is sent via network stream then why dont you use readpixel fast and then send that value? You can use writepixelfast to a buffer after you recieve it. |
| ||
Warner > I tought of that but the library it works with a picture file. Nate the great > Im not trying to make my life harder you know, if I could get the data in a more readable form, I would. : ) |
| ||
@Nate - because the pixels aren't simply stored pixel by pixel row by row in a jpeg, it is stored in the compressed jpeg format, which you'd need to either do as he says above, write to a file then load in, or learn the file format for jpeg and uncompress it himself in memory. |
| ||
I would use DevIL. Dunno if anyone wrapped it for B3D already or not. http://openil.sourceforge.net/features.php |
| ||
Okay Sacha, just to check: you have the complete contents of the JPEG, just saved in a bank, right? Create a file, and dump the bank contents one byte at a time with something like this:JPEG = WriteFile("image.jpg") For i = 1 To BankSize(JPEGBank) WriteByte JPEG,PeekByte(JPEGBank,i - 1) Next CloseFile JPEG Global Image = LoadImage("image.jpg") That's just off the top of my head, you'll probably need to fiddle with it for it to work. Cheers! |
| ||
See FiLoadFromBank.bb here. |
| ||
Yes adam this works and is what Im currently using, however this is the 'bad' solution (write a file then reading it to get data we already have. markcw > Thanks, thats seems to be exactly what I need, ill be trying that. : ) |