title: Load any Image into TImage from TStream
body: <p>I want to make a class to view images in any format. image is stored in blob field.</p>
  
  <p>I create:</p>
  
  <pre><code> const
     ImageType:array [0..6] of TGraphicClass=(TJpegimage, TBitmap, TWICImage,
                                              TGIFImage, TPNGImage, TMetafile,TIcon);
  
  procedure tImageView.LoadFromStream(AStrm: TStream);
  var
    Ext: string;
    NewGraphic: TGraphic;
    GraphicClass: TGraphicClass;
  
    i:integer;
    IsLoaded:boolean;
  begin
     IsLoaded:=false;
     for i:=0 to Length(ImageType)-1 do begin
        try
           GraphicClass:=ImageType[i];
           NewGraphic := GraphicClass.Create;
           if Astrm.Size&lt;&gt;0 then begin
              NewGraphic.LoadFromStream(Astrm);
              IsLoaded:=true;
              Break;
              end;
        except
           try
              NewGraphic.Free;
           finally
  
              end;
           end;
        end;
     if Isloaded then begin
        fImg.Picture.Assign(NewGraphic);
        NewGraphic.Free;
        end
     else begin
        raise EInvalidGraphic.Create('Unknow format image!!!!!!!');
        end;
     end;
  </code></pre>
  
  <p>If first type of image in "ImageType" not correct, then and correct type next index run exception. Why? I must call some init procedure?</p>