BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TBitmap from HBITMAP not resizing

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
André Ávila
Guest





PostPosted: Mon Nov 14, 2005 2:31 pm    Post subject: TBitmap from HBITMAP not resizing Reply with quote



Hello,

I'm a newbie regarding graphics programming, so I'm bit lost here. I'm
trying to write a simple zoom function, so I followed some suggestions I
read here at the group. For some reason, it doesn't work.

I have a TPictureBox inside a TScrollBox. I then get a HBITMAP and set it to
the Handle property of a TBitmap:

Graphics::TBitmap *m_Bmp = new Graphics::TBitmap;

void __fastcall TForm1::LoadImageButtonClick(TObject *Sender) {
HBITMAP hbmp = getImageAsHBITMAP(); // This is legacy code I must use

if (hbmp != NULL) {
m_Bmp->Handle = hbmp;
PaintBox1->SetBounds(0, 0, m_Bmp->Width, m_Bmp->Height);
}

// Reposition ScrollBox1...
}

In the Zoom button, I simply change the Height and Width of the TBitmap:

void __fastcall TForm1::ZoomInButtonClick(TObject *Sender)
{
m_Bmp->Height = m_Bmp->Height * 1.2;
m_Bmp->Width = m_Bmp->Width * 1.2;
PaintBox1->SetBounds(0, 0, m_Bmp->Width, m_Bmp->Height);

// Reposition ScrollBox1...
}

void __fastcall TForm1::ZoomOutButtonClick(TObject *Sender)
{
m_Bmp->Height = m_Bmp->Height * 0.8;
m_Bmp->Width = m_Bmp->Width * 0.8;
PaintBox1->SetBounds(0, 0, m_Bmp->Width, m_Bmp->Height);

// Reposition ScrollBox1...
}

I wrote the OnPaint method for the TPaintBox using BitBlt:

void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
BitBlt(PaintBox1->Canvas->Handle, 0, 0,
PaintBox1->Width, PaintBox1->Height,
m_Bmp->Canvas->Handle, 0, 0,
SRCCOPY);
}

As fas as I know, PaintBox1->SetBounds calls OnPaint, because the LoadImage
works fine. However zoom in and zoom out don't work.

Any ideas on what am I doing wrong?


Back to top
André Ávila
Guest





PostPosted: Mon Nov 14, 2005 2:33 pm    Post subject: Re: TBitmap from HBITMAP not resizing Reply with quote



Quote:
I have a TPictureBox inside a TScrollBox. I then get a HBITMAP and set it
to
the Handle property of a TBitmap:

Sorry, I meant a TPaintBox inside a TScrollBox.



Back to top
Jonathan Benedicto
Guest





PostPosted: Mon Nov 14, 2005 2:44 pm    Post subject: Re: TBitmap from HBITMAP not resizing Reply with quote



André Ávila wrote:
Quote:
In the Zoom button, I simply change the Height and Width of the
TBitmap:

That doesn't work because TBitmap doesn't automatically resize the original
image.

I'd do this:
void __fastcall TForm1::ZoomInButtonClick(TObject *Sender)
{
int PaintBoxWidth = PaintBox1->Width;
int PaintBoxHeight = PaintBox1->Height;

PaintBox1->SetBounds( 0, 0, ( (double)PaintBoxWidth * 1.2 ), (
(double)PaintBoxHeight * 1.2 ) );
// Reposition ScrollBox1...
}

void __fastcall TForm1::ZoomOutButtonClick(TObject *Sender)
{
int PaintBoxWidth = PaintBox1->Width;
int PaintBoxHeight = PaintBox1->Height;

PaintBox1->SetBounds( 0, 0, ( (double)PaintBoxWidth * 0.8 ), (
(double)PaintBoxHeight * 0.8 ) );
// Reposition ScrollBox1...
}

void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
PaintBox1->Canvas->StretchDraw( PaintBox1->ClientRect, m_Bmp );
}

HTH

Jonathan



Back to top
André Ávila
Guest





PostPosted: Mon Nov 14, 2005 6:37 pm    Post subject: Re: TBitmap from HBITMAP not resizing Reply with quote

Thank you very much, Jonathan. It now works perfectly.


"Jonathan Benedicto" <incorrect (AT) no (DOT) server> escreveu na mensagem
news:4378a29b (AT) newsgroups (DOT) borland.com...
Quote:
André Ávila wrote:
In the Zoom button, I simply change the Height and Width of the
TBitmap:

That doesn't work because TBitmap doesn't automatically resize the
original
image.

I'd do this:
void __fastcall TForm1::ZoomInButtonClick(TObject *Sender)
{
int PaintBoxWidth = PaintBox1->Width;
int PaintBoxHeight = PaintBox1->Height;

PaintBox1->SetBounds( 0, 0, ( (double)PaintBoxWidth * 1.2 ), (
(double)PaintBoxHeight * 1.2 ) );
// Reposition ScrollBox1...
}

void __fastcall TForm1::ZoomOutButtonClick(TObject *Sender)
{
int PaintBoxWidth = PaintBox1->Width;
int PaintBoxHeight = PaintBox1->Height;

PaintBox1->SetBounds( 0, 0, ( (double)PaintBoxWidth * 0.8 ), (
(double)PaintBoxHeight * 0.8 ) );
// Reposition ScrollBox1...
}

void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
PaintBox1->Canvas->StretchDraw( PaintBox1->ClientRect, m_Bmp );
}

HTH

Jonathan





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.