简体   繁体   English

如何将 sqlite 中的图像显示到 flex 数据网格中

[英]How to display images from sqlite into a flex datagrid

I have a number of thumbnail images (8K ish in length), stored in a sqlite database, encoded as base64 strings.我有许多缩略图(长度为 8K),存储在 sqlite 数据库中,编码为 base64 字符串。

I would like to retrieve these images and present them into a datagrid (along with some other information from the DB)我想检索这些图像并将它们呈现到数据网格中(以及来自数据库的一些其他信息)

The retrieval of information from the database works, but I cannot quite "see" how to connect the decoded result from the database to the datagrid, to display the images.从数据库中检索信息是可行的,但我不能完全“看到”如何将数据库中的解码结果连接到数据网格,以显示图像。

Below is some code, where I show (to simplify things) a simply DGrid and want to use the dataprovider to point to the select from the DB下面是一些代码,我在其中显示(为了简化)一个简单的 DGrid 并希望使用数据提供程序从 DB 指向 select

Any details to show how I need to change this code would be greatly appreciated:-)任何显示我需要如何更改此代码的细节将不胜感激:-)

  <mx:DataGrid id="dg2" dataProvider="{dp2}">
    <mx:columns>
      <mx:DataGridColumn headerText="Image"  dataField="image"  width="150"/>
    </mx:columns>
  </mx:DataGrid>

The code to generate the dp2 information is as follows.生成dp2信息的代码如下。 The result2 array is populated as expected and ldr appears to be populated, but imageBMap and (therefore) dp2 are null. result2 数组按预期填充,ldr 似乎已填充,但 imageBMap 和(因此)dp2 是 null。

    sql2.text = "SELECT image FROM  bookMarks;";
    sql2.execute();

    var result2:SQLResult = sql2.getResult();        
    var data2:Array = result2.data;

    var base64Dec:Base64Decoder;
    var byteArr:ByteArray;
    var bmap:Bitmap;
    var ldr:Loader = new Loader(); 
    base64Dec = new Base64Decoder();


    if(result2.data != null)
    {
      var numRows:int = result2.data.length;

      for(var i:int = 0; i < numRows; i++)
      {     
        for(var columnName:String in result2.data[i])
        {
          if(columnName == "image") // Normally there will be more than 1 column in the select, hence this check
          {
            base64Dec.decode(result2.data[i][columnName]);
            byteArr = base64Dec.toByteArray();                
            ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);                
            ldr.loadBytes(byteArr);
          } 
        } 
      } 
    } 
    var imageBMap:Bitmap = Bitmap(ldr.content);
    dp2 = ArrayCollection(imageBMap);
  }

  private function loaderComplete(event:Event):void
  {
    var loaderInfo:LoaderInfo = LoaderInfo(event.target);
    var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height, false, 0xFFFFFF);
    bitmapData.draw(loaderInfo.loader);        
  }

You need to use in itemRenderer to display the image:您需要在itemRenderer中使用来显示图像:

<mx:DataGridColumn headerText="Image" width="150">
    <mx:itemRenderer>
        <fx:Component>
            <s:Image source="{here you put the dataProvider}">
        </fx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM