zoukankan      html  css  js  c++  java
  • TcxGrid Column动态添加Image

          MyCol := TcxColumn.Create;
                ...
    
                MyCol.PropertiesClass := TcxImageProperties;
                ImageProps := TcxImageProperties(MyCol.Properties);
                ImageProps.Center := True;
                ImageProps.GraphicClassName := '';
                ImageProps.OnGetGraphicClass := GetThumbnailGraphicClass;
                ImageProps.Stretch := True;
                ...
    
    Procedure GetThumbnailGraphicClass:
    
    procedure TCORSA.GetThumbnailGraphicClass(AItem: TObject;
      ARecordIndex: Integer; APastingFromClipboard: Boolean;
      var AGraphicClass: TGraphicClass);
    begin
      if AnsiSAmeText(FThumbNailExtension, '.TIF') then
          AGraphicClass := TGraphicClass(GetClass('TTiffGraphic'))
      else
      if AnsiSAmeText(FThumbNailExtension, '.JPG') then
          AGraphicClass := TGraphicClass(GetClass('TJPEGImage'))
    end;
    
    The actual thumbnail data is loaded into the grid via streams:
    
                    MStream := TMemoryStream.Create;
                    Stream := TStringStream.Create('');
    
                    MStream.LoadFromFile(ThumbNail);
                    Stream.CopyFrom(MStream, MStream.Size);
    
                    FActiveGrid.DataController.SetValue(RowInfo.RecordIndex,
                                                        ThumbCol,
                                                        Stream.DataString);

    改进后的:

     

    function StreamToVar(Stream: TStream): OleVariant;
    var
          P: Pointer;
    begin
      Result := VarArrayCreate([0, Stream.size -1],Varbyte);
      P := VarArrayLock(Result);
      Try
        Stream.Position := 0;
        Stream.Read(P^, Stream.size);
      Finally
        VarArrayUnlock(Result);
      end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
      IRecIdx  :  Integer;
      stream : TMemoryStream;
    begin
      with cxGrid1TableView1.DataController do
      begin
        IRecIdx := AppendRecord;
        stream := TMemoryStream.Create();
        stream.LoadFromFile('H:pic随拍IMAG0002.jpg');
         stream.Position := 0;
        Values[IRecIdx,0] := StreamToVar(stream);
        stream.Free;
        Post;
      end;
    end;
  • 相关阅读:
    Android Studio 中关于NDK编译及jni header生成的问题
    为YAESU FT-817ND 增加频谱功能
    Nagios 安装配置
    ubuntu 13.10 Ralink RT3290 无线与蓝牙4.0的驱动安装
    golang全文搜索--使用sphinx
    GNU Radio 之 rtl-sdr
    OsmocomBB && Motorora C118
    OsmocomBB 编译安装
    Go 若干技巧
    Docker内核知识
  • 原文地址:https://www.cnblogs.com/starluck/p/3925863.html
Copyright © 2011-2022 走看看