如何使用图形单元将图像加载到Turbo Pascal

时间:2014-10-29 04:16:11

标签: turbo-pascal

我需要为Pascal程序加载一个bitimage,有没有办法做到这一点,或者我必须逐个像素地绘制?

2 个答案:

答案 0 :(得分:0)

通过使用图形单位,您可以在turbo pascal中加载BGI图形。

请参阅此内容以获取更多信息......

http://pascal-programming.info/lesson8.php

以下是上述链接中的示例代码...

Program Lesson8_Program1;
Uses Crt,Graph;
Var GraphicsDriver, GraphicsMode,
    ErrCode : Integer; 
  {two var's are needed for initialisation}
Begin
 Writeln('Initialising Graphics, please wait...');
 GraphicsDriver := Detect;
 InitGraph(GraphicsDriver, GraphicsMode,'');
 {IMPORTANT, read the following or 
  otherwise graphics will not work!! ;)}
 (*between the inverted commas,
   type in the path of the graphics BGI file
  (usually 'C:\TP\BGI'),
   OR
   change the dir in the file menu (PRESS Alt+F) 
   and roll down your mouse pointer to the 'change dir' 
   menu; then either type the path to the BGI file, 
   or go to C: -> TP -> BGI*)
 ErrCode := GraphResult;
 If GraphResult <> grOK then { <> means 'not equal to' }
  Begin
   ClrScr;
   Writeln('Graphics error occured: ',
            GraphErrorMsg(ErrCode));
   Writeln('If a file not found error is displayed above');
   Writeln('then, change the dir from the current');
   Writeln('location to C:\ -> TP -> BGI, '+
          +'from the file menu!');
   Readln;
   Halt(1);
  End Else
  Begin
   Randomize; 
   SetColor(Random(15) + 1); {Set text colour}
   {Output text at 20 pixels from the top of the screen, 
    and 20 other from the left side of the screen.}
   OutTextXY(20,20,'Welcome to the new generation 
                    of Pascal Programming:');
   OutTextXY(20,30,'Pascal Graphics!!');
   OutTextXY(25,70,'You will learn more 
                    graphics procedures and');
   OutTextXY(25,80,'functions, later in this lesson :-)');
   Readln;
  End; 
 CloseGraph;
End.

请参阅此内容以获取更多信息......

http://pascal-programming.info/lesson8.php

答案 1 :(得分:0)

据我记忆,Turbo pascal有功能

GetImage(X1, Y1, X2, Y2: integer; var BitMap)
PutImage(X, Y: integer; var BitMap; BitBlt: word);

BitMap只是位图的一块内存。这样,您可以从屏幕到内存获取图像,反之亦然。我认为从文件到屏幕获取图像没有直接的功能。但是如果光盘上的图像格式正确,可以将其加载到内存中,然后使用PutImage。