By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Image resize using GDI+?

P: n/a
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

--
www.integrated-dev-sol.co.uk
Remove 123 from email address to reply.
Anti spam and virus measure.
Dec 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
(1) create a PictureBox
(2) set the Image of the PictureBox to your Bitmap (form->Image = bitmap)
(3) add the PictureBox to your form (form->Controls->Add( picturebox ))
(4) set the Width and Height of your PictureBox.

The image should stretch to fill whatever dimensions you givethe PictureBox
(there might be a proprty of PictureBox you have to set a particular way to
get this behavior, but I think it's default is to stretch)...

[==P==]

"John Swan" <j.*********@ntlworld.com> wrote in message
news:Dz******************@newsfe4-win.ntli.net...
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

--
www.integrated-dev-sol.co.uk
Remove 123 from email address to reply.
Anti spam and virus measure.

Dec 12 '05 #2

P: n/a
Sorry. I did not explain correctly.

I would like this to be a batch process so I dont want to actually display
image.
Just create a lot of thumbnails of the images.

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...
(1) create a PictureBox
(2) set the Image of the PictureBox to your Bitmap (form->Image = bitmap)
(3) add the PictureBox to your form (form->Controls->Add( picturebox ))
(4) set the Width and Height of your PictureBox.

The image should stretch to fill whatever dimensions you givethe PictureBox (there might be a proprty of PictureBox you have to set a particular way to get this behavior, but I think it's default is to stretch)...

[==P==]

"John Swan" <j.*********@ntlworld.com> wrote in message
news:Dz******************@newsfe4-win.ntli.net...
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

--
www.integrated-dev-sol.co.uk
Remove 123 from email address to reply.
Anti spam and virus measure.


Dec 12 '05 #3

P: n/a
Ok, but now it gets a bit more complex. You could do the following (I
think):

Create an offscreen buffer bitmap. Get the Graphics object for it, use the
Graphics object and its DrawImage method to draw the image on the offscreen
buffer any size you want. Now create a new bitmap as a rectangle the size of
the drawn image on the offscreen, blit the image from offscreen to new
bitmap, and this new bitmap can be used as a thumbnail (and is not drawn on
the screen). Provided its big enough to hold your biggest thumbnail, you can
use the sane offscreen bitmap over and over (provided you Clear it before
each use)...

float m_W = thumb_w ;
float m_H = thumb_h ;
Bitmap^ image = gcnew Bitmap( filename) ;
Bitmap^ m_Offscreen = gcnew Bitmap( thumb_w, thumb_h) ;
Graphics^ m_Offscreen_Graphics = Graphics::FromImage( m_Offscreen ) ;
m_Offscreen_Graphics->DrawImage( image, 0, 0, m_W, m_H ) ;
Bitmap^ thumbnail = gcnew Bitmap( m_W, m_H ) ;
thumbnail->DrawImageUnscaled( m_Offscreen_Graphics, 0, 0 ) ;

[==P==]

"John Swan" <j.*********@ntlworld.com> wrote in message
news:vF****************@newsfe2-gui.ntli.net...
Sorry. I did not explain correctly.

I would like this to be a batch process so I dont want to actually display
image.
Just create a lot of thumbnails of the images.

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...
(1) create a PictureBox
(2) set the Image of the PictureBox to your Bitmap (form->Image = bitmap)
(3) add the PictureBox to your form (form->Controls->Add( picturebox ))
(4) set the Width and Height of your PictureBox.

The image should stretch to fill whatever dimensions you givethe

PictureBox
(there might be a proprty of PictureBox you have to set a particular way

to
get this behavior, but I think it's default is to stretch)...

[==P==]

"John Swan" <j.*********@ntlworld.com> wrote in message
news:Dz******************@newsfe4-win.ntli.net...
> 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
>
> --
> www.integrated-dev-sol.co.uk
> Remove 123 from email address to reply.
> Anti spam and virus measure.
>
>



Dec 12 '05 #4

P: n/a
Just out of interest. I posted this on a different newsgroup and the rely
which worked is as follows.
---------------------------------------------------------
"John Swan" <j.*********@ntlworld.com> schrieb:
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;
}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
---------------------------------------------------

Turns out that drawimage just draws the image to another image. I think the
term DrawImage is a little ambigious as it isn't actually drawing anything
but it works.

Anyway.
Cheers

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl... Ok, but now it gets a bit more complex. You could do the following (I
think):

Create an offscreen buffer bitmap. Get the Graphics object for it, use the
Graphics object and its DrawImage method to draw the image on the offscreen buffer any size you want. Now create a new bitmap as a rectangle the size of the drawn image on the offscreen, blit the image from offscreen to new
bitmap, and this new bitmap can be used as a thumbnail (and is not drawn on the screen). Provided its big enough to hold your biggest thumbnail, you can use the sane offscreen bitmap over and over (provided you Clear it before
each use)...

float m_W = thumb_w ;
float m_H = thumb_h ;
Bitmap^ image = gcnew Bitmap( filename) ;
Bitmap^ m_Offscreen = gcnew Bitmap( thumb_w, thumb_h) ;
Graphics^ m_Offscreen_Graphics = Graphics::FromImage( m_Offscreen ) ;
m_Offscreen_Graphics->DrawImage( image, 0, 0, m_W, m_H ) ;
Bitmap^ thumbnail = gcnew Bitmap( m_W, m_H ) ;
thumbnail->DrawImageUnscaled( m_Offscreen_Graphics, 0, 0 ) ;

[==P==]

"John Swan" <j.*********@ntlworld.com> wrote in message
news:vF****************@newsfe2-gui.ntli.net...
Sorry. I did not explain correctly.

I would like this to be a batch process so I dont want to actually display image.
Just create a lot of thumbnails of the images.

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...
(1) create a PictureBox
(2) set the Image of the PictureBox to your Bitmap (form->Image = bitmap) (3) add the PictureBox to your form (form->Controls->Add( picturebox )) (4) set the Width and Height of your PictureBox.

The image should stretch to fill whatever dimensions you givethe

PictureBox
(there might be a proprty of PictureBox you have to set a particular way
to
get this behavior, but I think it's default is to stretch)...

[==P==]

"John Swan" <j.*********@ntlworld.com> wrote in message
news:Dz******************@newsfe4-win.ntli.net...
> 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
>
> --
> www.integrated-dev-sol.co.uk
> Remove 123 from email address to reply.
> Anti spam and virus measure.
>
>



Dec 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.