CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2016
    Posts
    9

    CImage reverse dimension cx<->cy !

    Only if i load pics taken vertically (so what width is < of height).
    Example: Pic “strFoto” have width of 1000px and height of 3000px.

    CImage img;
    img.Load(strFoto);
    int cx = img.GetWidth(); // return 3000!!!!
    int cy = img.GetHeight();// return 1000!!!

    Some advice please
    Thanks

  2. #2
    Join Date
    Aug 2006
    Posts
    231

    Re: CImage reverse dimension cx<->cy !

    Are you sure that your image is not corrupt or incomplete? Can you share it?

  3. #3
    Join Date
    Jul 2016
    Posts
    9

    Re: CImage reverse dimension cx<->cy !

    Hi TubularX,
    Yes i m shure.
    I did tests with pics from Windows Phone and Samsung S4 but is equal...and I see "right" is on Smartphones and Windows but Cimage return reverse!
    However if I open with Paint and save with other name these apparently equal work with CImage.

    I enclose a photo.

    Thank U.Name:  WP_20160403_15_42_25_Pro.jpg
Views: 114
Size:  23.1 KB

  4. #4
    Join Date
    Jul 2016
    Posts
    9

    Re: CImage reverse dimension cx<->cy !

    As you see the photo is taken vertically, although well here you see horizontal as with CImage, while various viewers on Windows and even the simple Paint the show correctly.

    Thanks

  5. #5
    Join Date
    Aug 2006
    Posts
    231

    Re: CImage reverse dimension cx<->cy !

    I tried with the file "WP_20160403_15_42_25_Pro.jpg" that you shared.

    The result is as expected:
    cx: 600
    cy: 338

    However, the width is not less than the height in the image you enclosed!

    Of course, based on the motive, a human might argue that the width and height are reversed.

    But to the computer, the width is always just a range of pixels in the x-axis and the height in y-axis.

  6. #6
    Join Date
    Aug 2006
    Posts
    231

    Re: CImage reverse dimension cx<->cy !

    even the simple Paint the show correctly.
    Paint also shows it as 600 x 338...

    Name:  image.jpg
Views: 123
Size:  38.8 KB

  7. #7
    Join Date
    Jul 2016
    Posts
    9

    Re: CImage reverse dimension cx<->cy !

    Hold on...the original photo has
    cx: 1728
    cy: 3072

    As you can see below Name:  Immagine.jpg
Views: 122
Size:  45.3 KB

  8. #8
    Join Date
    Jul 2016
    Posts
    9

    Re: CImage reverse dimension cx<->cy !

    I think the site that compresses

  9. #9
    Join Date
    Aug 2006
    Posts
    231

    Re: CImage reverse dimension cx<->cy !

    OK, then there's probably some orientation metadata in your original jpg file.

    Check this out:
    http://stackoverflow.com/questions/5...ation-metadata

    Edit: Sorry, I just noticed the examples above are in Java. I guess you need a C++ solution. I'm not sure how to deal with it using CImage, but I found a solution with QT: http://imonad.com/photo/jpeg-exif-orientation/

    Edit #2: It's also possible with GDI+: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    Last edited by TubularX; July 26th, 2016 at 07:11 AM.

  10. #10
    Join Date
    Jul 2016
    Posts
    9

    Re: CImage reverse dimension cx<->cy !

    You think so too ... I think anyone doing a test with your smartphone to have my problema.....io I tried with Windows Phone with Samsung and equals.
    I read a bit of the link and is pretty much the same thing
    ... though that absurd thing ☺
    thank you
    Hello.

  11. #11
    Join Date
    Jul 2016
    Posts
    9

    Thumbs up [RESOLVED] CImage reverse dimension cx<->cy !

    Then ... the problem is just the orientation of the images inserted in the Exif file format
    So would process all the Exif, but, looking at Exif (and trying) I found that:
    If Big-Endian (Motorola) encoding file (like on Windows Phone) the byte to 0x38 identifies the orientation, while for Little Endian (Intel) (as on Samsung) byte is 0x4F.
    Of the 8 possible values of expected orientation, in my case I need only 3:
    If that byte==3 means that the image is rotate of 180.
    If that byte==6 means that the image is rotate of 90CW.
    If that byte==8 means that the image is rotate of 270CW.

    The rest in my case is not interesting …then I avoid to process all the Exif, do I hurt???


    Code sample:

    unsigned char b[0x4F]
    CFile f(filename, CFile::modeRead);
    f.Read(b, sizeof(b) );

    unsigned char ucRotate = 0;

    // Is a Exif file format?
    if (b[0]==0xFF && b[1]==0xD8 && b[2]==0xFF &&
    b[3]==0xE1 && b[6]==’E’ && b[7]==’x’ && b[8]==’i’ && b[9]==’f’)
    {
    // is a Big Endian?
    if (b[0xC]==’M’ && b[0xD]==’M’)
    {
    ucRotate=b[0x37];
    }

    // is a Little Endian?
    if (b[0xC]==’I’ && b[0xD]==’I’)
    {
    ucRotate=b[0x4E];
    }

    }

    f.close();


    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured