如何定义流或者使用流的方式
就是将Image1中的图片转换成流,再写入文件中

解决方案 »

  1.   

    type        //定义记录集[结构]
        studentrecord=record      //Word
              xh,xm:string[8];          //学号,姓名
              yw,sx:integer;            //定义科目
       ImageBufName:integer;            //图片文件名
       ImageBufSize:integer;            //图片长度
       ImageBuffers:PChar;              //图片内容
    end;
    上面是记录集的结构............................
      

  2.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;type
      TForm1 = class(TForm)
        Image1: TImage;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
    fileheader:tbitmapfileheader; //位图的文件头
    infoheader:tbitmapinfoheader; //位图的信息头
    stream:tfilestream;//文件流对象
    localbmp:tbitmap; //位图对象
    linelen:integer;  //每一行像素长度
    clipleft,cliptop,clipwidth,clipheight,bytecount:integer;
    i:integer;
    //j:integer; //位图倒立显示,变量
    begin
    form1.Width:=screen.Width;
    form1.Height:=screen.Height;
    form1.Top:=0;
    form1.Left:=0;
    self.DoubleBuffered:=true; //建立双缓冲
    cliptop:=0;
    clipwidth:=image1.Width;
    clipheight:=image1.Height;
    //将位图加载到文件流中
    stream:=tfilestream.Create('2.bmp',fmopenread or fmsharedenywrite);
    localbmp:=tbitmap.Create;//创建位图实例
    stream.Read(fileheader,sizeof(tbitmapfileheader));//读取文件头数据
    stream.Read(infoheader,sizeof(tbitmapinfoheader));//读取信息头数据
    localbmp.Width:=clipwidth;
    localbmp.Height:=clipheight;
    localbmp.PixelFormat:=pf24bit;//设置为24位位图
    bytecount:=3;
    clipleft:=0;
    //j:=clipheight-1;//位图倒立显示,变量
    linelen:=(bytecount*infoheader.biWidth+3) shr 2 shl 2;
    for i:=cliptop to cliptop + clipheight -1 do
    begin
    //设置新的指针位置
    stream.Position :=integer(fileheader.bfOffBits) + linelen * (infoheader.biHeight-1-i) + bytecount * clipleft;
    //stream.Read(localbmp.scanline[j-i]^,clipwidth * bytecount); //位图倒立显示
    //将新的数据读进文件流中
    stream.Read(localbmp.scanline[i-cliptop]^,clipwidth * bytecount);//位图正常显示
    end;
    image1.Picture.Bitmap.Assign(localbmp);
    end;end.
    我几个月前学图形编程的代码
      

  3.   

    建议你再看看记录的相关内容。比如D5开发人员指南一书里的记录部分。
    因为要储存图片,你所要的实际上是一个自定义数据库。
    可以考虑使用ACCESEE之类的数据库。
    我做过自定义数据库,可以储存任何类型的数据。
    盒子里好像有过资料管理类的源码,我做的也点像那,不过更复杂一些。
      

  4.   

    ACCESS之类的数据库方式,这个我会呀,我不想用这个,
    我就是想自己定义一个记录集的数据结构方式
    文件内容结构如下: 
    就是数据类型不统一呀 
    [A0000001.JPG+56+sdfsdfsd] 
    图片文件+图片长度+图片内容 
    字符型 +数据型  +二进制型
      

  5.   

    记录文件的结构是
    学号 姓名 语文 数学  照片
    每行为一个记录,包括上行信息段
    type        //定义记录集[结构] 
        studentrecord=record      //Word 
              xh,xm:string[8];          //学号,姓名 
              yw,sx:integer;            //定义科目 
      ImageBufName:integer;            //图片文件名 
      ImageBufSize:integer;            //图片长度 
      ImageBuffers:PChar;              //图片内容 
    end; 
    t:studentrecord;
    f:file of studentrecord;
    write(f,t);
    这样,就直接写入到数据中..........