1

I am trying to reduce load times and memory by loading only part of an image instead of the entire image. This can be a segment from any coordinate on the image.

Assuming I have an image of 100MB, I would like to load 1 corner of the image (so around 25MB), thus saving ~75MB.

I have tried out JPEG2000.Net which claims to load only part of an image but after testing it seems to still use a lot of memory (never less than the original image).

The image format is not an issue. I would prefer to retain the original quality of the image as much as possible.

Parrotmaster
  • 647
  • 1
  • 7
  • 27
  • Does it need to be WPF or Windows Forms/GDI+? – Patrick Hofman Mar 04 '19 at 09:47
  • Is it a option to load just the exeif preview thumbnail? https://stackoverflow.com/questions/24780250/read-exif-thumbnail-from-jpeg – fubo Mar 04 '19 at 09:47
  • @fubo It should be possible to get the entire image by combining cut out segments or get a segment only. This segment can be from any place in the image. The thumbnail would (as I understand it) always encompass the entire image. – Parrotmaster Mar 04 '19 at 09:59
  • @PatrickHofman No. I only want to load the segment of the image and then turn it into a byte array. – Parrotmaster Mar 04 '19 at 10:00
  • as it is compressed, you need to decompress your image or decompress at least as long you don't have the complete part of your image parsed. You need to store only the part of the image you need and you can stop parsing once it is fully stored. I'm not sure it's possible with your library :-) – Laurent Lequenne Mar 04 '19 at 10:03
  • 1
    @Parrotmaster I thought of a YX-problem, that's why I suggested that exeif-approach wich reduces the loading time. If the quality of the exeif is good enough, you could slice pieces out of that one after you loaded it. – fubo Mar 04 '19 at 10:04
  • This is not supported by the .NET image loading implementations. You will basically have to either find a 3rd party library with support for this, or re-implement loading of the image formats you need to support. – Lasse V. Karlsen Mar 04 '19 at 10:06
  • 1
    https://github.com/BitMiracle/libjpeg.net/blob/master/Jpeg/Program_Decompression.cs check from line 80, you see that it reads the complete file, but you can limit to your area. – Laurent Lequenne Mar 04 '19 at 10:08
  • @LaurentLequenne Nice idea, but in this code the jpeg is read line by line. At least you would need a way to skip lines before starting to read. – NoDataDumpNoContribution Mar 04 '19 at 10:25
  • You can not... As it is compressed you can only read the image from the beginning, but you can store only the data needed. Now if you think you will reuse your image, you should cache your image, so that if you need to load a part that has already been read you don't need to decode again. – Laurent Lequenne Mar 04 '19 at 10:30
  • @LaurentLequenne Would it be possible to read until the last pixel that you need and then stop (So if my segment starts at pixel 200 and ends at 600, I load 0 through 600 even if the image goes up to 1000)? Obviously, this way you will almost always load more than requested, but you can still avoid loading everything (in my example, you don't load 400 pixels). – Parrotmaster Mar 04 '19 at 10:33
  • I guess yeah .. You need to read full lines. and store the lines and maybe (part of the line only) thay you need to display . once you have stored all the bytes of your image, you can stop the read – Laurent Lequenne Mar 04 '19 at 11:17

0 Answers0