Podobne
- Strona startowa
- Borland Delphi 7 Developer's Guide
- Programming Windows Games in Borland C
- Borland C Builder 6 Book
- Christie Agatha Wczesne sprawy Poirota (SCAN da
- Christie Agatha Godzina zero (2)
- Mistrz harfiarzy z Pern
- Zywe kamienie BERENT
- Diabel z wiezienia dluznikow Antonia Hodgston
- Adobe Illustrator PL Podrecznik uzytkownika
- Joanna Chmielewska Krowa Niebianska
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- spartakus.htw.pl
Cytat
Do celu tam się wysiada. Lec Stanisław Jerzy (pierw. de Tusch-Letz, 1909-1966)
A bogowie grają w kości i nie pytają wcale czy chcesz przyłączyć się do gry (. . . ) Bogowie kpią sobie z twojego poukładanego życia (. . . ) nie przejmują się zbytnio ani naszymi planami na przyszłość ani oczekiwaniami. Gdzieś we wszechświecie rzucają kości i przypadkiem wypada twoja kolej. I odtąd zwyciężyć lub przegrać - to tylko kwestia szczęścia. Borys Pasternak
Idąc po kurzych jajach nie podskakuj. Przysłowie szkockie
I Herkules nie poradzi przeciwko wielu.
Dialog półinteligentów równa się monologowi ćwierćinteligenta. Stanisław Jerzy Lec (pierw. de Tusch - Letz, 1909-1966)
[ Pobierz całość w formacie PDF ]
.Left, FShapeRect.Top);Image1->Canvas->LineTo(FShapeRect.Right, FShapeRect.Bottom);break;case csRectangle:Image1->Canvas->Rectangle(FShapeRect.Left, FShapeRect.Top,FShapeRect.Right, FShapeRect.Bottom);break;case csEllipse:file:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch07.htm (15 of 48) [10/10/2000 1:12:56 AM]Ch 7 -- GraphicsImage1->Canvas->Ellipse(FShapeRect.Left, FShapeRect.Top,FShapeRect.Right, FShapeRect.Bottom);break;default:;}}void __fastcall TForm1::FormMouseMove(TObject *Sender,TShiftState Shift, int X, int Y){if (FDrawing){Image1->Canvas->Pen->Mode = pmNotXor;if (FShapeRect.Right != -32000)DrawShape();FShapeRect.Right = X;FShapeRect.Bottom = Y;DrawShape();}}void __fastcall TForm1::SpeedButton1Click(TObject *Sender){FCurrentShape = TCurrentShape(dynamic_cast(Sender)->Tag);}void __fastcall TForm1::Brush1Click(TObject *Sender){ColorDialog1->Color = FBrushColor;if (ColorDialog1->Execute())FBrushColor = ColorDialog1->Color;}void __fastcall TForm1::Pen1Click(TObject *Sender){file:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch07.htm (16 of 48) [10/10/2000 1:12:56 AM]Ch 7 -- GraphicsColorDialog1->Color = FPenColor;if (ColorDialog1->Execute())FPenColor = ColorDialog1->Color;}void __fastcall TForm1::SpeedButton5Click(TObject *Sender){FPenThickness = dynamic_cast(Sender)->Tag;}void __fastcall TForm1::Save1Click(TObject *Sender){if (SaveDialog1->Execute()){Image1->Picture->SaveToFile(SaveDialog1->FileName);}}void __fastcall TForm1::Open1Click(TObject *Sender){if (OpenDialog1->Execute()){Image1->Picture->LoadFromFile(OpenDialog1->FileName);}}void __fastcall TForm1::Exit1Click(TObject *Sender){Close();}The key change from the DrawShapes program is that all of the Canvas operations are performed on the Canvas of a TImagecontrol rather than directly on the Canvas of a form:Image1->Canvas->MoveTo(FShapeRect.Left, FShapeRect.Top);Image1->Canvas->LineTo(FShapeRect.Right, FShapeRect.Bottom);A TImage control is designed explicitly for the type of operations undertaken by this program.In particular, it maintains an internalbitmap into which images are automatically drawn.When it comes time to save the picture you have created, you can do so with one line of code:void __fastcall TForm1::Save1Click(TObject *Sender)file:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch07.htm (17 of 48) [10/10/2000 1:12:56 AM]Ch 7 -- Graphics{if (SaveDialog1->Execute()){Image1->Picture->SaveToFile(SaveDialog1->FileName);}}Loading a file into memory from disk is also a simple one-line operation:void __fastcall TForm1::Open1Click(TObject *Sender){if (OpenDialog1->Execute()){Image1->Picture->LoadFromFile(OpenDialog1->FileName);}}Both of the preceding calls assume that you have dropped a TOpenDialog onto the main form of your application.TheTOpenDialog object is extremely easy to use, so you should have no trouble learning how to use it from the online help.NOTE: When I opt not to explain an object such as TOpenDialog, my intention is not to ignore the needs of this book'sreaders, but rather to avoid inserting boring, repetitious information into the book.If you really crave a reference otherthan the online help for this kind of information, you should check the bookstore for introductory texts that cover this kindof material.If you want a bit more flexibility, and desire to have a separate TBitmap object which you can use for your own purposes, it is easy tocreate one from the image you created with this program.To proceed, just create a TBitmap object, and then use the Assign methodto copy the picture from the TImage control to your bitmap:Graphics::TBitmap *Bitmap = new Graphics::TBitmap();Bitmap->Assign(Image1->Picture->Graphic);Bitmap->SaveToFile(SaveDialog1->FileName);delete Bitmap;In this example I save the bitmap to file and then delete the object when I am through with it.In the context of the current program, thisdoesn't make a great deal of sense.However, code like this demonstrates some of the functionality of the TBitmap object.I qualifythe reference to TBitmap with Graphics.Hpp, because there are two TBitmap declarations in the header files included in mostBCB programs.Working with MetafilesBitmaps are very convenient and are often the best way to work with graphic images.However, BCB also lets you work with enhancedmetafiles.Metafiles are collections of shapes drawn into a device context.Internally, they are little more than a list of GDI calls that can beplayed back on demand to create a picture.Metafiles have two big advantages over bitmaps:They are very small.The same image that might take hundreds of KB to save in bitmaps can often be saved in a metafile of just10 or 20 thousand bytes.Because metafiles consist of a series of shapes, you can, at least potentially, iterate through the list of shapes in a picture and editthem one at a time.This can give you a very powerful ability to precisely edit the contents of a picture.file:///D|/DOWNLOAD/charlie_calvert's_borland_c++_builder_unleashed/ch07.htm (18 of 48) [10/10/2000 1:12:56 AM]Ch 7 -- GraphicsThe disadvantage of metafiles is that they must consist only of a series of GDI calls.As a result, you can't easily transform aphotograph or a scanned image into a metafile.Metafiles are best defined as a simple way of preserving text, or as a simple means ofstoring a series of fairly simple shapes such as a line drawing.In the hands of a good artist, however, you can get metafiles to showsome fairly powerful images.(See Figure 7.2.)FIGURE 7.2.A grayscale version of a colorful metafile that ships with Microsoft Office shows some of the power of this technology.There are two types of metafiles available to Windows users.One has the extension.WMF, and is primarily designed for use in the16-bit world.The second type of file has the extension.EMF, for Enhanced Metafile.These latter types of files are designed for use inthe 32-bit world.I find them much more powerful than their 16-bit cousins.The code shown in the forthcoming MetaShapes program is designed to work only with enhanced metafiles.BCB will save a file as aregular metafile if you give it an extension of.WMF, and it will save it as an enhanced metafile if you give it an extension of.EMF.When using BCB, it is best to stick with enhanced metafiles.If you have some.WMF files you want to use with BCB, you might wantto find a third-party tool that will convert your.WMF into an.EMF.The MetaShapes program is very similar to the DrawShapes and BitmapShapes programs.It has the same capabilities as theBitmapShapes program in terms of its capability to save and preserve images, only it works with metafiles rather than bitmaps.Metafiles are many times smaller than standard.BMP files.There is no TImage control for metafiles, so you have to do a little more work to make this system function properly.In particular,you have to explicitly open a metafile and then draw directly into it, as shown in Listing 7.4 and 7.5.Listing 7.4.The header for the MetaShapes program.///////////////////////////////////////// Main
[ Pobierz całość w formacie PDF ]