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. Handling images

Handling images

Scheduled Pinned Locked Moved C / C++ / MFC
c++phpsysadminhelptutorial
5 Posts 2 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.
  • H Offline
    H Offline
    hint_54
    wrote on last edited by
    #1

    Greetings I'm building a website that has an automate engine to display pictures. There is a menu that lets you choose the event. The directories are organized like this: - root -- Weddings --- WBlaBla1 ---- Pic1 ---- Pic2 ---- PicN --- WBlaBla2 ---- Pic1 ---- Pic2 ---- PicN --- SomeOtherTypeOfEventWithTheSameStructureHasPreviously -- SomethingElse The purpose is to sell the pictures, so it will have a cart shop. The problem is that I have the pictures in very high resolution, and I want to prevent the users from accessing the pictures in this format (i.e. 1807x1772). I know that PHP can handle this (i.e. display thumbnails) but the thing is that, with time, the events will be more and more, and this consumes space in the server, and the space is rented, offcourse. So I had the idea of writting a C++ application that converts ALL the pictures in a directory to a low resolution version AND with a water mark, that way the sysadmin could convert the pictures before uploading them to the server. What I would like to ask is how to do this in C++, I mean, not search the pictures nor that sort of things, but how to lower the resolution and add the water mark to them. The pictures are all in JPG format. Best regards hint_54

    M 2 Replies Last reply
    0
    • H hint_54

      Greetings I'm building a website that has an automate engine to display pictures. There is a menu that lets you choose the event. The directories are organized like this: - root -- Weddings --- WBlaBla1 ---- Pic1 ---- Pic2 ---- PicN --- WBlaBla2 ---- Pic1 ---- Pic2 ---- PicN --- SomeOtherTypeOfEventWithTheSameStructureHasPreviously -- SomethingElse The purpose is to sell the pictures, so it will have a cart shop. The problem is that I have the pictures in very high resolution, and I want to prevent the users from accessing the pictures in this format (i.e. 1807x1772). I know that PHP can handle this (i.e. display thumbnails) but the thing is that, with time, the events will be more and more, and this consumes space in the server, and the space is rented, offcourse. So I had the idea of writting a C++ application that converts ALL the pictures in a directory to a low resolution version AND with a water mark, that way the sysadmin could convert the pictures before uploading them to the server. What I would like to ask is how to do this in C++, I mean, not search the pictures nor that sort of things, but how to lower the resolution and add the water mark to them. The pictures are all in JPG format. Best regards hint_54

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Th easiest way I know of (on Windows) is to use GDI+ to load and save the images. A simple stretchblt to a smaller, proportioned size is all that's necessary...load, resize, and save.

      H 1 Reply Last reply
      0
      • M Mark Salsbery

        Th easiest way I know of (on Windows) is to use GDI+ to load and save the images. A simple stretchblt to a smaller, proportioned size is all that's necessary...load, resize, and save.

        H Offline
        H Offline
        hint_54
        wrote on last edited by
        #3

        I'll take a look ;) thx hint_54

        1 Reply Last reply
        0
        • H hint_54

          Greetings I'm building a website that has an automate engine to display pictures. There is a menu that lets you choose the event. The directories are organized like this: - root -- Weddings --- WBlaBla1 ---- Pic1 ---- Pic2 ---- PicN --- WBlaBla2 ---- Pic1 ---- Pic2 ---- PicN --- SomeOtherTypeOfEventWithTheSameStructureHasPreviously -- SomethingElse The purpose is to sell the pictures, so it will have a cart shop. The problem is that I have the pictures in very high resolution, and I want to prevent the users from accessing the pictures in this format (i.e. 1807x1772). I know that PHP can handle this (i.e. display thumbnails) but the thing is that, with time, the events will be more and more, and this consumes space in the server, and the space is rented, offcourse. So I had the idea of writting a C++ application that converts ALL the pictures in a directory to a low resolution version AND with a water mark, that way the sysadmin could convert the pictures before uploading them to the server. What I would like to ask is how to do this in C++, I mean, not search the pictures nor that sort of things, but how to lower the resolution and add the water mark to them. The pictures are all in JPG format. Best regards hint_54

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Here ya go...a holiday present :) (I ripped the GetEncoderClsid() right out of the GDI+ docs

          int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
          {
          UINT num = 0; // number of image encoders
          UINT size = 0; // size of the image encoder array in bytes

          ImageCodecInfo\* pImageCodecInfo = NULL;
          
          GetImageEncodersSize(&num, &size);
          if(size == 0)
          	return -1;  // Failure
          
          pImageCodecInfo = (ImageCodecInfo\*)(malloc(size));
          if(pImageCodecInfo == NULL)
          	return -1;  // Failure
          
          GetImageEncoders(num, size, pImageCodecInfo);
          
          for(UINT j = 0; j < num; ++j)
          {
          	if( wcscmp(pImageCodecInfo\[j\].MimeType, format) == 0 )
          	{
          		\*pClsid = pImageCodecInfo\[j\].Clsid;
          		free(pImageCodecInfo);
          		return j;  // Success
          	}    
          }
          
          free(pImageCodecInfo);
          return -1;  // Failure
          

          }

          ...

          // Resize an 640x480 image to 320x240
          // (I already know this source image is 640x480 - In real life use
          //   SrcBitmap.GetWidth() and SrcBitmap.GetHeight() to get an image's dimensions
          
          Gdiplus::Bitmap SrcBitmap(L"D:\\\\Source\\\\Images\\\\sony-cybershot.jpg", FALSE);
          Gdiplus::Bitmap DstBitmap(320,240,SrcBitmap.GetPixelFormat()); 
          Graphics DstGraphics(&DstBitmap);
          DstGraphics.DrawImage(&SrcBitmap, 0, 0, 320, 240);
          CLSID jpgClsid;
          GetEncoderClsid(L"image/jpeg", &jpgClsid);
          DstBitmap.Save(L"D:\\\\Source\\\\Images\\\\sony-cybershot\_test.jpg", &jpgClsid, NULL);
          
          H 1 Reply Last reply
          0
          • M Mark Salsbery

            Here ya go...a holiday present :) (I ripped the GetEncoderClsid() right out of the GDI+ docs

            int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
            {
            UINT num = 0; // number of image encoders
            UINT size = 0; // size of the image encoder array in bytes

            ImageCodecInfo\* pImageCodecInfo = NULL;
            
            GetImageEncodersSize(&num, &size);
            if(size == 0)
            	return -1;  // Failure
            
            pImageCodecInfo = (ImageCodecInfo\*)(malloc(size));
            if(pImageCodecInfo == NULL)
            	return -1;  // Failure
            
            GetImageEncoders(num, size, pImageCodecInfo);
            
            for(UINT j = 0; j < num; ++j)
            {
            	if( wcscmp(pImageCodecInfo\[j\].MimeType, format) == 0 )
            	{
            		\*pClsid = pImageCodecInfo\[j\].Clsid;
            		free(pImageCodecInfo);
            		return j;  // Success
            	}    
            }
            
            free(pImageCodecInfo);
            return -1;  // Failure
            

            }

            ...

            // Resize an 640x480 image to 320x240
            // (I already know this source image is 640x480 - In real life use
            //   SrcBitmap.GetWidth() and SrcBitmap.GetHeight() to get an image's dimensions
            
            Gdiplus::Bitmap SrcBitmap(L"D:\\\\Source\\\\Images\\\\sony-cybershot.jpg", FALSE);
            Gdiplus::Bitmap DstBitmap(320,240,SrcBitmap.GetPixelFormat()); 
            Graphics DstGraphics(&DstBitmap);
            DstGraphics.DrawImage(&SrcBitmap, 0, 0, 320, 240);
            CLSID jpgClsid;
            GetEncoderClsid(L"image/jpeg", &jpgClsid);
            DstBitmap.Save(L"D:\\\\Source\\\\Images\\\\sony-cybershot\_test.jpg", &jpgClsid, NULL);
            
            H Offline
            H Offline
            hint_54
            wrote on last edited by
            #5

            Djii :-O thx !! ;) hint_54

            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