|
|
|
date: Tue, 25 Mar 2008 13:06:03 -0700,
group: microsoft.public.platformsdk.gdi
back
Re: JPEG CONVERSION
Sorry about the slow response!
GDI+ makes it easy, but its interface is C++. I've heard there's a way to
use it from C, but I have no experience using it that way.
If you can use C++, then you can do the conversion in 3 lines of code using
the shared ATL/MFC CImage class.
If you want to use GDI+ directly, it takes more code...
Following is an example (all of this is wrapped nicely in the CImage class)
//-------------------------------------------------------------------------
// C++ sample using straight GDI+:
// Note: GetEncoderClsid() Taken from the GDI+ documentation :)
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
}
// GDI+ - Convert JPEG to BMP
#pragma push_macro("new")
#undef new
ULONG dwToken;
Gdiplus::GdiplusStartupInput input;
Gdiplus::GdiplusStartupOutput output;
Gdiplus::Status status = Gdiplus::GdiplusStartup(&dwToken, &input,
&output);
if(status == Gdiplus::Ok)
{
Gdiplus::Bitmap *pSrcBitmap = new Gdiplus::Bitmap(L"e:\\test.jpg", FALSE);
CLSID bmpClsid;
GetEncoderClsid(L"image/bmp", &bmpClsid);
pSrcBitmap->Save(L"e:\\test.bmp", &bmpClsid);
delete pSrcBitmap;
Gdiplus::GdiplusShutdown(dwToken);
}
#pragma pop_macro("new")
//-------------------------------------------------------------------------
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
"ChangChiTheGraphics" wrote
in message news:690863A1-F7EA-41C2-94F4-FB259486E273@microsoft.com...
> Hi Mark,
>
> I am using C language, and my platform is Windows XP, service pak 2.
>
> But if necessary, I can use C++ language because I am compiling
> with Visual C++ 2008.
>
> Thank you for your help,
>
> ChangChiThe Graphics
>
>
> "Mark Salsbery [MVP]" wrote:
>
>> What language are you using?
>>
>> Mark
>>
>> --
>> Mark Salsbery
>> Microsoft MVP - Visual C++
>>
>>
>> "ChangChiTheGraphics"
>> wrote
>> in message news:B17BFD39-7F71-45C5-8892-4E20F4F7E4C2@microsoft.com...
>> > I am coverting JPEG picture format into BMP format, and vice versa.
>> > I wonder if I can use conversion functions used by the windows so that
>> > I
>> > do
>> > not have to develop seperately.
>> > How do I get to access these function ?
>> > JPEG to BMP, and BMP to JPEG.
>> >
>> > Thanks,
>> > SpottyTheDog
>> >
date: Mon, 31 Mar 2008 13:57:55 -0700
author: Mark Salsbery [MVP] MarkSalsbery[MVP]@newsgroup.nospam
Re: JPEG CONVERSION
"Richard Russell" wrote in message
news:427de807-cf7d-4d30-ab78-b8e03e5f16d3@1g2000prf.googlegroups.com...
> On Mar 31, 9:57 pm, "Mark Salsbery [MVP]"
> <MarkSalsbery[MVP]@newsgroup.nospam> wrote:
>> GDI+ makes it easy, but its interface is C++. I've heard there's a way to
>> use it from C, but I have no experience using it that way.
>
> Of course you can call C++ methods, or implement a C++ interface, in
> straight C. Indeed the header files often include appropriate
> declarations for that. However what you're probably thinking about is
> the GDI+ flat interface:
>
> http://msdn2.microsoft.com/en-us/library/ms533969
How can you call C++ methods from C? Static methods used as a callback with
C calling convention?
C doesn't know anything about classes, the new operator, etc.
Anyway, thanks for the link - that's what I was referring to! :)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
>
> Richard.
> http://www.rtrussell.co.uk/
> To reply by email change 'news' to my forename.
date: Thu, 10 Apr 2008 10:31:54 -0700
author: Mark Salsbery [MVP] MarkSalsbery[MVP]@newsgroup.nospam
|
|