zoukankan      html  css  js  c++  java
  • bmp和Variant的转换

    procedure TForm2.VariantToBMP(aValue : OleVariant;var aBmp:TBitmap); 
    var 
       Stream : TMemoryStream; 
    begin 
    try 
      Stream := TMemoryStream.Create;

      VariantToStream (aValue,Stream); 
      aBmp.LoadfromStream(Stream);

    finally 
       VariantClear(aValue); 
       Stream.free; 
    end; 
    end;

    procedure TForm2.BMPToVariant(aBmp : TBitmap; var aVariant:OleVariant); 
    var 
      Stream        : TMemoryStream; 
    begin 
        try 
           Stream := TMemoryStream.Create;

           Image1.Picture.Bitmap.SaveToStream(Stream);

           StreamToVariant(Stream, aVariant); 
        finally 
           Stream.Free; 
       end; 
    end;

    rocedure TForm2.VariantToStream (const v : olevariant; 
                                      Stream : TMemoryStream); 
    var 
      p : pointer; 
    begin 
      Stream.Position := 0; 
      Stream.Size := VarArrayHighBound (v, 1) - VarArrayLowBound(v,  1) + 1; 
      p := VarArrayLock (v); 
      Stream.Write (p^, Stream.Size); 
      VarArrayUnlock (v); 
      Stream.Position := 0; 
    end;

    procedure TForm2.StreamToVariant (Stream : TMemoryStream; var v : OleVariant); 
    var 
      p : pointer; 
    begin 
      v := VarArrayCreate ([0, Stream.Size - 1], varByte); 
      p := VarArrayLock (v); 
      Stream.Position := 0; 
      Stream.Read (p^, Stream.Size); 
      VarArrayUnlock (v); 
    end; 

  • 相关阅读:
    3、总结
    三分及小例题
    约瑟夫问题的推导
    对于联通块的处理
    扩展欧几里得与二元不定方程
    js 阻止事件捕获
    原生xhr发送JSON
    $timeout
    Angularjs Ng_repeat中实现复选框选中并显示不同的样式
    为什么用Object.prototype.toString.call(obj)检测对象类型?
  • 原文地址:https://www.cnblogs.com/yzryc/p/6374910.html
Copyright © 2011-2022 走看看