Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. The Image is being displayed upside down :(

The Image is being displayed upside down :(

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionhelp
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Christian Graus

    If you're using C++/CLI, you have no need of FreeImage, .NET will load all the image formats you're likely to need, and save them too. Windows bitmaps are stored bottom line first. Perhaps FreeImage is inverting them ? Christian Graus - Microsoft MVP - C++

    S Offline
    S Offline
    signbit
    wrote on last edited by
    #3

    Dear Sir, May be it's inverting it, but is there any cure? However I still have to use FreeImage, since I am working on an image processing application and all the code has to be in Standard C (so that it can be ported easily), I am using CLR/.NET only because I need a good looking interface. - A programmer's national anthem; "AAAAAHHHHH!!!!"

    C S 2 Replies Last reply
    0
    • S signbit

      Dear Sir, May be it's inverting it, but is there any cure? However I still have to use FreeImage, since I am working on an image processing application and all the code has to be in Standard C (so that it can be ported easily), I am using CLR/.NET only because I need a good looking interface. - A programmer's national anthem; "AAAAAHHHHH!!!!"

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #4

      signbit wrote:

      May be it's inverting it, but is there any cure?

      Not short of inverting it back :-)

      signbit wrote:

      all the code has to be in Standard C (so that it can be ported easily),

      What, for the 3 people in the world using Linux who pay for software, or the 50 odd who do the same for Mac ?

      signbit wrote:

      ), I am using CLR/.NET only because I need a good looking interface.

      That's just silly. You don't need CLR to make your UI look good, they had good looking UIs long before .NET existed. Christian Graus - Microsoft MVP - C++

      S 1 Reply Last reply
      0
      • S signbit

        Hello, I am creating a Bitmap with the following code:

        image = gcnew Bitmap(FreeImage_GetWidth(document->currentImage),
        FreeImage_GetHeight(document->currentImage), FreeImage_GetLine(document->currentImage),
        System::Drawing::Imaging::PixelFormat::Format24bppRgb,
        (IntPtr)FreeImage_GetScanLine(document->currentImage, 0));

        Image information (Height, Width, ScanLine0 and etc) is obtained from FreeImage (the open source library I am using for image handling). When the image is displayed, it displays upside down, can any one tell me what might be the problem, how can I make it correct? I'll be grateful. - A programmer's national anthem; "AAAAAHHHHH!!!!"

        N Offline
        N Offline
        normanS
        wrote on last edited by
        #5

        Windows bitmaps are normally "upside down", but Windows understands normal (upside down) bitmaps as well as "right-way-up" bitmaps - check the MSDN documentation on bitmap headers. As far as I remember, "right-way-up" bitmaps have negative height, so in your code, try changing:

        info.biHeight = height;

        to

        info.biHeight = -height;

        (or whatever the equivalent is in C++.) I use this technique with a StretchDIBits call, and it works there, but it may not work with all display APIs.

        S M 2 Replies Last reply
        0
        • S signbit

          Dear Sir, May be it's inverting it, but is there any cure? However I still have to use FreeImage, since I am working on an image processing application and all the code has to be in Standard C (so that it can be ported easily), I am using CLR/.NET only because I need a good looking interface. - A programmer's national anthem; "AAAAAHHHHH!!!!"

          S Offline
          S Offline
          signbit
          wrote on last edited by
          #6

          Also, If I use the following code for image creation, it works just fine. But I don't like this code, it's a 4 step procedure and it should be liking the processor very much.

          if(image)
          delete image;

          FIMEMORY *hMem;
          hMem = FreeImage_OpenMemory();
          FreeImage_SaveToMemory(FIF_BMP, document->currentImage, hMem);

          BYTE *pBuffer;
          DWORD size;

          FreeImage_AcquireMemory(hMem, &pBuffer, &size);

          UnmanagedMemoryStream^ memStream =
          gcnew UnmanagedMemoryStream(pBuffer, size);
          image = gcnew Bitmap(memStream);

          FreeImage_CloseMemory(hMem);

          - A programmer's national anthem; "AAAAAHHHHH!!!!"

          1 Reply Last reply
          0
          • C Christian Graus

            signbit wrote:

            May be it's inverting it, but is there any cure?

            Not short of inverting it back :-)

            signbit wrote:

            all the code has to be in Standard C (so that it can be ported easily),

            What, for the 3 people in the world using Linux who pay for software, or the 50 odd who do the same for Mac ?

            signbit wrote:

            ), I am using CLR/.NET only because I need a good looking interface.

            That's just silly. You don't need CLR to make your UI look good, they had good looking UIs long before .NET existed. Christian Graus - Microsoft MVP - C++

            S Offline
            S Offline
            signbit
            wrote on last edited by
            #7

            A couple of things: One can make a good interface even in WIN32 API (I have worked on it, and I am sure I can). But we now longer make it, do we? why? we need the ease... Yes, I am using CLR only because It supports Windows Forms and I can concentrate on core algorithms when I don't have to worry for the UI. There is a lot of speed difference between Managed and Unmanaged code (MS may have made several gaint steps in improving it's CLR but still it's a layer between You and the processor). If I had luxeries on that, I would have used C# in first place, I am using VC++ because I can access/write the C code more easily here. There is a chance that the application may have to be burned into some custome hardware (and only C can be burned into HW at this time). Yes I need to care about those 3 people who use Linux because it doesn't harm me. doest it? :) - A programmer's national anthem; "AAAAAHHHHH!!!!" -- modified at 0:38 Tuesday 28th February, 2006

            C 1 Reply Last reply
            0
            • N normanS

              Windows bitmaps are normally "upside down", but Windows understands normal (upside down) bitmaps as well as "right-way-up" bitmaps - check the MSDN documentation on bitmap headers. As far as I remember, "right-way-up" bitmaps have negative height, so in your code, try changing:

              info.biHeight = height;

              to

              info.biHeight = -height;

              (or whatever the equivalent is in C++.) I use this technique with a StretchDIBits call, and it works there, but it may not work with all display APIs.

              S Offline
              S Offline
              signbit
              wrote on last edited by
              #8

              Dear Sir, Yup! I know the structure, I tried to trick CLR with that ;) (i.e. negative height), but It didn't work out. :) - A programmer's national anthem; "AAAAAHHHHH!!!!"

              1 Reply Last reply
              0
              • S signbit

                A couple of things: One can make a good interface even in WIN32 API (I have worked on it, and I am sure I can). But we now longer make it, do we? why? we need the ease... Yes, I am using CLR only because It supports Windows Forms and I can concentrate on core algorithms when I don't have to worry for the UI. There is a lot of speed difference between Managed and Unmanaged code (MS may have made several gaint steps in improving it's CLR but still it's a layer between You and the processor). If I had luxeries on that, I would have used C# in first place, I am using VC++ because I can access/write the C code more easily here. There is a chance that the application may have to be burned into some custome hardware (and only C can be burned into HW at this time). Yes I need to care about those 3 people who use Linux because it doesn't harm me. doest it? :) - A programmer's national anthem; "AAAAAHHHHH!!!!" -- modified at 0:38 Tuesday 28th February, 2006

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #9

                signbit wrote:

                Yes I need to care about those 3 people who use Linux because it doesn't harm me. doest it?

                And yet, here you have an issue because you're using third party libraries. An issue that would go away if you were not concerned about cross platform code. So yes, it does hurt you. It costs you time and it costs you options. Christian Graus - Microsoft MVP - C++

                S 1 Reply Last reply
                0
                • C Christian Graus

                  signbit wrote:

                  Yes I need to care about those 3 people who use Linux because it doesn't harm me. doest it?

                  And yet, here you have an issue because you're using third party libraries. An issue that would go away if you were not concerned about cross platform code. So yes, it does hurt you. It costs you time and it costs you options. Christian Graus - Microsoft MVP - C++

                  S Offline
                  S Offline
                  signbit
                  wrote on last edited by
                  #10

                  No It doesn't, since if using 3rd party libraries and portable code would have been an issue, we wouldn't have this forum full of messages that target the problems for pure CLR/.NET code. It's just any other problem that I would have been facing during my development. and does it cost me options? ;) Nah, I have the option of porting my library to any platform I choose, I don't need to stick to Windows, So I have more options... Anyway, I think I am getting away from the original problem, won't be reply any such messages because It's not a debate. - A programmer's national anthem; "AAAAAHHHHH!!!!"

                  1 Reply Last reply
                  0
                  • N normanS

                    Windows bitmaps are normally "upside down", but Windows understands normal (upside down) bitmaps as well as "right-way-up" bitmaps - check the MSDN documentation on bitmap headers. As far as I remember, "right-way-up" bitmaps have negative height, so in your code, try changing:

                    info.biHeight = height;

                    to

                    info.biHeight = -height;

                    (or whatever the equivalent is in C++.) I use this technique with a StretchDIBits call, and it works there, but it may not work with all display APIs.

                    M Offline
                    M Offline
                    mbue
                    wrote on last edited by
                    #11

                    This is correct! If it doesn't work there is something wrong with your used libraries.

                    S 1 Reply Last reply
                    0
                    • M mbue

                      This is correct! If it doesn't work there is something wrong with your used libraries.

                      S Offline
                      S Offline
                      signbit
                      wrote on last edited by
                      #12

                      What is correct? giving negative height? I did that and CLR returned an exception... - A programmer's national anthem; "AAAAAHHHHH!!!!"

                      M 1 Reply Last reply
                      0
                      • S signbit

                        What is correct? giving negative height? I did that and CLR returned an exception... - A programmer's national anthem; "AAAAAHHHHH!!!!"

                        M Offline
                        M Offline
                        mbue
                        wrote on last edited by
                        #13

                        the post from 'normanS' was correct. It is possible to store images in a reverse line order. To indentify that the header contains a negative image size. If your library crashes there is something wrong in your libraries.

                        N S 2 Replies Last reply
                        0
                        • M mbue

                          the post from 'normanS' was correct. It is possible to store images in a reverse line order. To indentify that the header contains a negative image size. If your library crashes there is something wrong in your libraries.

                          N Offline
                          N Offline
                          normanS
                          wrote on last edited by
                          #14

                          Thanks for the support. Unfortunately, many libraries do not support negative heights. This monster called Windows is just to big for most companies to keep up. This includes some Microsoft SDK stuff.

                          1 Reply Last reply
                          0
                          • M mbue

                            the post from 'normanS' was correct. It is possible to store images in a reverse line order. To indentify that the header contains a negative image size. If your library crashes there is something wrong in your libraries.

                            S Offline
                            S Offline
                            signbit
                            wrote on last edited by
                            #15

                            I said it's not my libraries that crash, it's .NET that crashes (my library returns the values as expected) - A programmer's national anthem; "AAAAAHHHHH!!!!"

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups