Determining the size of a JPEG (JFIF) image

后端 未结 4 1214
北荒
北荒 2020-12-23 14:36

I need to find the size of a JPEG (JFIF) image. The image is not saved as a stand-alone file, so I can\'t use GetFileSize or any other API such this one (the im

4条回答
  •  青春惊慌失措
    2020-12-23 14:57

    Since you don't have any language posted, I'm not sure that this will work, but:

    Can you Stream.Seek(0, StreamOffset.End); and then take the stream's position?

    Please be specific about what framework you are using.

    The real fact of the matter is, if the file header doesn't specify the expected size, you have to seek (or read) to the end of the image.

    EDIT

    Since you are trying to stream multiple files, you will want to use a streaming friendly container format.

    OGG should be a nice fit for this.

    JPEG is actually already streaming friendly, but you must guarantee that each file has a valid terminator before sending it down the stream or else you run the risk of crashing your app with unexpected input.

提交回复
热议问题