我已經從數據庫中,把圖片存到內存流中了,
現在就是要對內存流中的不同格式的圖片做出不
同的處理,請大俠們,出來指點一下,這個要怎
處理

解决方案 »

  1.   

    把图片读到TMemorystream中 然后 readbuffer,writebuffer ,copymemory。。
    看你具体的要求了
      

  2.   

    我關鍵是要判斷在內存流中圖片是什麼格式的,如*.BMP,*.jpg
    大俠具體怎麼寫,指點一下,謝謝
      

  3.   

    如果只是判断BMP、JPG、GIF图片,倒是有一个简单的方法,用数据流判断,因为BMP、GIF、JPG格式的文件流有标识符的,分别如下:  
      名称                 宽度             标识符  
      BMP                 2位                 BM  
      JPG                 10位               chr($FF)+chr($D8)+chr($FF)+chr($E0)+chr($00)+chr($10)+'JFIF'  
      GIF                 3位                 GIF
      

  4.   


     hongqi162(失踪的月亮)  
    這個代碼要怎麼寫呢,
      

  5.   

    var
      ms:TMemoryStream;
      b:Array[0..1] of byte;
      s:string;
    begin
      ms:=TMemoryStream.Create;
      if self.OpenDialog1.Execute then
      begin
        ms.LoadFromFile( self.OpenDialog1.FileName );
        ms.ReadBuffer( b,sizeof( b ) );
        setlength( s,sizeof(b) );
        move(b[0],s[1],sizeof(b) );
      end;
      ms.Free;BMP图片b内容为BM
    JPG图片b内容为$FF $D8
      

  6.   

    BMP b: ($42, $4D)JPG b: ($FF, $D8)
      

  7.   

    建议新建一个字段,根据需要可选择tinyint,smallint或int,表示类型。
      

  8.   


    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      BmpImg:TBitmap;
      JpgImg:TJPEGImage;
      ms:TmemoryStream;
      PhothoType:string;//文件类型
    begin
    {
      ADODataSet1.Active:=false;
      ADODataSet1.CommandText:='select * from employee where emplyee_id=:@Employee_id ';
      ADODataSet1.Parameters.ParamByName('@Employee_id').Value := edit1.Text;
      ADODataSet1.Active:=true;  if ADODataSet1.IsEmpty then
      begin
        showmessage('em');
      end;  PhothoType := ADODataSet1.fieldByName('phothoType').AsString;
      ms := TmemoryStream.Create();
      TBlobField(ADODataSet1.FieldByName('photho')).SaveToStream(ms);
      ms.Position := 0;
      if UpperCase(PhothoType)='.BMP' then
      begin
        BmpImg := TBitmap.Create();
        BmpImg.LoadFromStream(ms);
        Image1.Picture.Assign(BmpImg);
      end else if UpperCase(PhothoType)='.JPG' then
      begin
        JpgImg := TJPEGImage.Create();
        JpgImg.LoadFromStream(ms);
        Image1.Picture.Assign(JpgImg);
      end;   }  LoadPhotoFromDB( 'employee', 'emplyee_id', 'photho', edit1.Text, Image1);
    end;procedure TForm1.LoadPhotoFromDB(ATableName, KeyFieldName, PhotoFieldName, KeyValue: string;
      Img: TImage);
    var
      adsDataSet: TADODataSet;
      JpgImg:TJPEGImage;
      PhotoStream: TMemoryStream;
    begin
      PhotoStream := TMemoryStream.Create;
      try
        Img.Picture.Assign(nil);
        adsDataSet := TADODataSet.Create(nil);
        adsDataSet.Connection := ADOConnection1;
        with adsDataSet do
        try
          Active := False;
          CommandText := 'Select ' + PhotoFieldName + ' From ' + ATableName
            + ' Where ' + KeyFieldName + '=' + QuotedStr(KeyValue);
          Active := True;
          if (RecordCount > 0) then
          begin
            if TBlobField(FieldByName(PhotoFieldName)).BlobSize <= 0 then
              Exit;
            if not FieldByName(PhotoFieldName).IsBlob then
              Exit;
            TBlobField(FieldByName(PhotoFieldName)).SaveToStream(PhotoStream);
            PhotoStream.Position := 0;        JpgImg := TJPEGImage.Create();
            JpgImg.LoadFromStream(PhotoStream);
            Img.Picture.Assign(JpgImg);
          end
          else begin
            Img.Picture.Assign(nil);
            Exit;
          end;
        except
          raise Exception.Create('读取图片失败.');
        end;
      finally
        FreeAndNil(adsDataSet);
        PhotoStream.Free;
      end;
    end;