FreeImageAPI cannot set Resolution for JPEG2000 images?

Help
KhoaPham
2013-11-26
2013-11-28
  • KhoaPham
    KhoaPham
    2013-11-26

    Hi all, this is my code

    private void CheckImg(string xfile, string outfile)
    {
    try
    {
    FIBITMAP dib = FreeImage.LoadEx(xfile);
    FIBITMAP dibTemp = dib;
    uint X = FreeImage.GetResolutionX(dib);
    uint Y = FreeImage.GetResolutionY(dib);
    bitMap = FreeImage.GetBitmap(dib);
    DeSkew deSkew = new DeSkew();
    deSkew.New(bitMap);
    double angle = deSkew.GetSkewAngle();
    dibTemp = FreeImage.Rotate(dibTemp, (double)angle);
    FreeImage.SetResolutionX(dibTemp, X);//but not effect
    FreeImage.SetResolutionY(dibTemp, Y);//but not effect
    bitMap = FreeImage.GetBitmap(dibTemp);
    FindDegree(bitMap);

                Rectangle rec = new Rectangle(left -20, top - 20, right - left + 35, bot - top + 35);//(left, top,bitMap.Width,bitMap.Height);                
                FreeImage.Unload(dib);
                FreeImage.Unload(dibTemp);
    
                using (Bitmap crop = bitMap.Clone(rec, bitMap.PixelFormat))
                {     
                   //crop.SetResolution(300, 300);
                    FreeImage.SaveBitmap(crop, outfile, FREE_IMAGE_FORMAT.FIF_JP2, FREE_IMAGE_SAVE_FLAGS.DEFAULT);
                    crop.Dispose();
                }
            }
            catch
            {
    
                ProcessEx(outfile, xfile, 3);
            }
            finally
            {
                bitMap.Dispose();
    
                GC.Collect();
            }
        }
    

    my image input have resolution is (300,300) but output image cannot set same resolution with input image.
    Who's give me solution?
    Thanks

     
  • Hervé Drolon
    Hervé Drolon
    2013-11-26

    Hi,

    The OpenJPEG library (internally used by FreeImage) doesn't read nor write the "Resolution box".
    That's why you can't save the resolution.
    You can fill an issue here :
    http://code.google.com/p/openjpeg/issues/list

    Hervé

     
  • KhoaPham
    KhoaPham
    2013-11-28

    Thanks Drolon. Follow your post, FreeImage cannot read or write Resolution for a JPEG 2000 image, then, why does it have function SetResolution. It's useless?

     
  • Carsten Klein
    Carsten Klein
    2013-11-28

    Hi,

    no, the function is not useless. While the image is loaded (aka. in memory) you can change and set almost everything, including metadata, resolution, backcolor etc. However, FreeImage is plugin-driven and each plugin decides which information to write into a file.

    Some file formats do not even support all the information, that is available in memory (as an example, the TARGA format does not contain a resolution). On the other side, some of the plugins do not have support for reading and/or writing all the image data that is supported by a certain image format (not supporting resolution with JPEG2000 for example).

    The latter case you could call a limitation of FreeImage or even a bug if you like.

    Carsten