CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Bmp to JPG

  1. #1
    Join Date
    Feb 2006
    Posts
    169

    Bmp to JPG

    Does any one know a routine/ method to change an image from Bmp to a JPG?

    Thanks

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: Bmp to JPG

    You can use Image Class of GDI+.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Bmp to JPG

    Or cxImage, but this might be a library too big for this task only.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Dec 2008
    Posts
    114

    Re: Bmp to JPG

    You don't need anything.
    Just use Win32 SHC api , which convert any graphic format

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Bmp to JPG

    Quote Originally Posted by carl666 View Post
    You don't need anything.
    Just use Win32 SHC api , which convert any graphic format
    Hi Carl,
    In this and few other posts you are mentioning some mysterious native Win32 API to work with JPEG, PNG, etc.
    Would you be so kind to name some of these API for the benefit of those of us who is unfamiliar with the subject?
    Thank you!
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  6. #6
    Join Date
    May 2009
    Posts
    140

    Re: Bmp to JPG

    + what SHC api?

  7. #7
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    Re: Bmp to JPG

    You could use this COM dll which has a very easy to use interface to convert bitmaps to jpegs.
    You need to rename imagehandler.zip to imagehandler.cab and then you can extract the contained dll.
    Attached Files Attached Files

  8. #8
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Bmp to JPG

    There's the CImage class that can do this too (since at least VS2003 IIRC).

  9. #9
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: Bmp to JPG

    Here is the GDI+ code using the Image class to do it.

    Code:
    #include <GdiPlus.h>
    
    #pragma comment(lib, "gdiplus")
    
    void foo()
    {
    	using namespace Gdiplus;
    	GdiplusStartupInput gdiplusStartupInput;
    	ULONG_PTR gdiplusToken;
    	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    	{
    		Image* pImage = Image::FromFile(L"D:\\abc.bmp", true);
    
    		CLSID clsid;
    		GetEncoderClsid(L"image/jpeg", &clsid);
    		pImage->Save(L"D:\\abc.jpg", &clsid);
    
    		delete pImage;
    	}
    	GdiplusShutdown(gdiplusToken);
    }
    
    int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
    {
    	using namespace Gdiplus;
    	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
    }

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