How do you resize an image in managed C++ .net using GDI or GDI?

  • Thread starter Thread starter John Swan
  • Start date Start date
J

John Swan

Hello.

I'm trying to create a simple program that amongst other things creates a
thumbnail of an image (Bitmap) to a set size determined by the user in
pixels?
The problem is: All of the examples I have seen so far are in c#.
Can anyone please provide reference to a c++ managed version.

Thanks.
John
 
John Swan said:
I'm trying to create a simple program that amongst other things creates a
thumbnail of an image (Bitmap) to a set size determined by the user in
pixels?
The problem is: All of the examples I have seen so far are in c#.
Can anyone please provide reference to a c++ managed version.

C++/CLI sample (requires a reference to "System.Drawing.dll"):

\\\
using namespace System;
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
using namespace System::Drawing::Imaging;

int main(array<System::String ^> ^args)
{
Bitmap ^bmp1 = gcnew Bitmap(L"C:\\WINDOWS\\Angler.bmp");
Bitmap ^bmp2 = gcnew Bitmap(
(int)(bmp1->Width * 0.1),
(int)(bmp1->Height * 0.1),
PixelFormat::Format24bppRgb
);
Graphics ^g = Graphics::FromImage(bmp2);
g->InterpolationMode = InterpolationMode::HighQualityBicubic;
g->DrawImage(bmp1, 0, 0, bmp2->Width, bmp2->Height);
bmp2->Save(L"C:\\Test.bmp");
return 0;
}
///
 
Thanks for the speedy reply.

I dont actually wish to draw the image.
I would like this too be a batch process and it would therefore be
considerably quicker in no drawing is done.
Any help would be appreciated.
 
John Swan said:
I dont actually wish to draw the image.
I would like this too be a batch process and it would therefore be
considerably quicker in no drawing is done.

That's exactly what the sample is doing. The code can be used in a console
application. 'DrawImage' is used to draw the resized version of the image
onto another bitmap which will be persisted by calling its 'Save' method
later on.
 
Back
Top