RAD Studio VCL Reference
|
Specifies the vertical size of the graphic in pixels.
property Height: Integer;
__property int Height;
Use Height to determine the height of the graphic image. Each descendant graphic object defines its own Get and Set methods to access the Height property.
C++ Examples:
/* This example converts a specified icon to a bitmap. To run this example, add an image, a button, and an Open dialog to a form. Name the button ConvertIcon2Bitmap, and add the following code as its OnClick event handler. */ #include <memory> //for STL auto_ptr class void __fastcall TForm1::ConvertIcon2BitmapClick(TObject *Sender) { OpenDialog1->DefaultExt = ".ICO"; OpenDialog1->Filter = "icons (*.ico)|*.ICO"; OpenDialog1->Options << ofOverwritePrompt << ofFileMustExist << ofHideReadOnly; if (OpenDialog1->Execute()) { std::auto_ptr<TIcon> pi(new Graphics::TIcon); AnsiString as; pi->LoadFromFile(OpenDialog1->FileName); as = ChangeFileExt(OpenDialog1->FileName,".BMP"); Image1->Width = pi->Width; Image1->Height = pi->Height; Image1->Canvas->Draw(0, 0, pi.get()); Image1->Picture->SaveToFile(as); ShowMessage(OpenDialog1->FileName + " Saved to " + as); } }
/* This example shows how to draw directly to a Bitmap. It loads a bitmap from a file and then copies it to another bitmap twice it's size. Then the two bitmaps are displayed on the form canvas. */ #include <memory> //for STL auto_ptr class void __fastcall TForm1::Button1Click(TObject *Sender) { std::auto_ptr<Graphics::TBitmap> Bitmap(new Graphics::TBitmap); std::auto_ptr<Graphics::TBitmap> BigBitmap(new Graphics::TBitmap); TRGBTriple *ptr, *bigPtr; // use a (byte *) for pf8bit color TPixelFormat pixForm, bigpixForm; try { Bitmap->LoadFromFile("../littlefac.bmp"); pixForm = Bitmap->PixelFormat; bigpixForm = BigBitmap->PixelFormat; Bitmap->PixelFormat = pf24bit; BigBitmap->PixelFormat = pf24bit; BigBitmap->Height = Bitmap->Height * 2; BigBitmap->Width = Bitmap->Width * 2; for (int y = 0; y < Bitmap->Height; y++) { ptr = reinterpret_cast<TRGBTriple *>(Bitmap->ScanLine[y]); for (int x = 0; x < Bitmap->Width; x++) { int bx = x * 2; int by = y * 2; bigPtr = reinterpret_cast<TRGBTriple *>(BigBitmap->ScanLine[by]); bigPtr[bx] = ptr[x]; bigPtr[bx + 1] = ptr[x]; bigPtr = reinterpret_cast<TRGBTriple *>(BigBitmap->ScanLine[by + 1]); bigPtr[bx] = ptr[x]; bigPtr[bx + 1] = ptr[x]; } } Canvas->Draw(0, 0, Bitmap.get()); Canvas->Draw(200, 200, BigBitmap.get()); } catch (...) { ShowMessage("Could not load or alter bitmap"); } }
Delphi Examples:
{ This example converts a specified icon to a bitmap. To run this example, add an image, a button, and an Open dialog to a form. Name the button ConvertIcon2Bitmap, and add the following code as its OnClick event handler. } procedure TForm1.ConvertIcon2BitmapClick(Sender: TObject); var s : string; Icon: TIcon; begin OpenDialog1.DefaultExt := '.ICO'; OpenDialog1.Filter := 'icons (*.ico)|*.ICO'; OpenDialog1.Options := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ]; if OpenDialog1.Execute then begin Icon := TIcon.Create; try Icon.Loadfromfile(OpenDialog1.FileName); s:= ChangeFileExt(OpenDialog1.FileName,'.BMP'); Image1.Width := Icon.Width; Image1.Height := Icon.Height; Image1.Canvas.Draw(0,0,Icon); Image1.Picture.SaveToFile(s); ShowMessage(OpenDialog1.FileName + ' Saved to ' + s); finally Icon.Free; end; end; end;
{ This example shows how to draw directly to a Bitmap. It loads a bitmap from a file and then copies it to another bitmap twice it's size. Then the two bitmaps are displayed on the form canvas. } procedure TForm1.Button1Click(Sender: TObject); type TRGBTripleArray = ARRAY[Word] of TRGBTriple; pRGBTripleArray = ^TRGBTripleArray; // use a PByteArray for pf8bit color var x,y : Integer; bx, by : Integer; BitMap, BigBitMap : TBitMap; P, bigP : pRGBTripleArray; pixForm, bigpixForm : TPixelFormat; begin BitMap := TBitMap.create; BigBitMap := TBitMap.create; try BitMap.LoadFromFile('littlefac.bmp'); pixForm := BitMap.PixelFormat; bigpixForm := BigBitMap.PixelFormat; BitMap.PixelFormat := pf24bit; BigBitMap.PixelFormat := pf24bit; BigBitMap.Height := BitMap.Height * 2; BigBitMap.Width := BitMap.Width * 2; for y := 0 to BitMap.Height - 1 do begin P := BitMap.ScanLine[y]; for x := 0 to BitMap.Width - 1 do begin bx := x * 2; by := y * 2; bigP := BigBitMap.ScanLine[by]; bigP[bx] := P[x]; bigP[bx + 1] := P[x]; bigP := BigBitMap.ScanLine[by + 1]; bigP[bx] := P[x]; bigP[bx + 1] := P[x]; end; end; Canvas.Draw(0, 0, BitMap); Canvas.Draw(200, 200, BigBitMap); finally BitMap.Free; BigBitMap.Free; end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|