No, the size of a long raw is only known when all data has been fetched. You can alternatively store the length in a separate number column, which you have to maintain in your application.
An even better option is to use a BLOB column of course, for which you can determine the length without fetching any data.
Unfortunately, I'm working with a legacy application and can't change the type. I guess that I'll just have to do the loop and keep realloc'ing the memory for the image.