2011-10-19 42 views
0

我需要從舊數據庫MS SQL 6.5進行數據轉換,現在我有店面形象問題裏面MS SQL 6.5,該圖像存儲都OLE數據意味着老應用程序接口這個MS SQL 6.5實際上將圖像存儲爲圖像類型中的ole。當我SELECTBLOB成團塊在PowerBuilder我需要此團塊送入ole_1.objectdata,然後轉換此ole_1.objectdata成所需的長度,以便被輸出到磁盤上的位圖文件,我已提取的這個翻譯代碼從專家 - 在「將Blob打印到bmp/jpg」(由Buasuwan發佈,但無法設法獲取該dll,因爲該帖子是舊帖子)交換。它做工精細我的BLOB的60%轉換爲位圖,而有關文件大小的剩餘產空視圖,就不能認爲它只是。這裏是代碼,我希望一些大師有可以幫助我與OLE轉換成位圖轉換爲位圖的問題在PowerBuilder

Blob lb_image 

    SelectBLOB picture_image into :lb_image 
    from individual 
    where individual_object_id='200506061121430020' 
    using SQLCA; 

    if SQLCA.sqlcode<>0 then 
     messagebox("cannot connect","cannot connect") 
    end if 


    if(len(lb_image)>0) then 


    ole_1.objectdata=lb_image 


    gf_convertbmp(ole_1.objectdata,ls_path) 


    end if 

我gf_convertbmp如下

long   ll_index, ll_len, ll_length 
    integer  li_FileNum 

    // Find Keyword 'BM' for starting Bitmap File 


    ll_len = Len(lb_ole_data) 

    ll_index = 1 

    blob  lb_bm 
    lb_bm = blob('BM') 
    do while ll_index <= ll_len 

     if BlobMid(lb_ole_data, ll_index, 2) = lb_bm then 

     exit 
     end if 

     ll_index++; 
    loop 

    // Find Length of Image 


     ll_length = long(asc(char(BlobMid(lb_ole_data, ll_index - 4, 1)))) + & 
       long(asc(char(BlobMid(lb_ole_data, ll_index - 3, 1)))) * 256 + & 
       long(asc(char(BlobMid(lb_ole_data, ll_index - 2, 1)))) * 65536 

     // Save Bitmap to File 


     li_FileNum = FileOpen(filename, StreamMode!, Write!, LockWrite!, Replace!) 


     // Write Bitmap Data 


    do while ll_length > 0 
      if ll_length > 32000 then 
      FileWrite(li_FileNum, BlobMid(lb_ole_data, ll_index, 32000)) 
      else 
      FileWrite(li_FileNum, BlobMid(lb_ole_data, ll_index, ll_length)) 
      exit 
      end if 
     ll_index += 32000 
     ll_length -= 32000 
     loop 



     FileClose(li_FileNum) 

回答

0

如果它真的是一個OLE包位圖,你是最好的方法(或至少我使用的)是打開數據作爲olestream,然後在包含數據的流中查找Ole10Native存儲。

// ls_storage is filename where data is written out 
ll_rc = lole_storage.Open (ls_storage) 

//Check to see that the Ole10Native storage exists. 
ls_streamname = Char(1) + 'Ole10Native' 
lole_storage.MemberExists (ls_streamname, lb_objectexists)   
IF lb_objectexists THEN 
    //Start 4 bytes into the storage to get the file 
    li_startat = 4    
ELSE 
    Return -1 
END IF 

ll_rc = lole_stream.Open(lole_storage, ls_streamname, stgRead!, stgExclusive!) 

//Get the length of the OLE stream 
ll_rc = lole_stream.Length (ll_streamlen) 


//Determine how many times to call Read 
//read returns a maximum or 32765 characters at a time 
//We are going to Seek to the first position, so don't include it in the 
//calculations. Also note that the Seek is zero-indexed, so we remove one 
//from the startat for our calcs 
ll_streamlen = ll_streamlen - (li_startat - 1) 
IF ll_streamlen > ll_chunk THEN 
    IF Mod(ll_streamlen, ll_chunk) = 0 THEN 
     ll_loops = ll_streamlen/ll_chunk 
    ELSE 
     ll_loops = (ll_streamlen/ll_chunk) + 1 
    END IF 
ELSE 
    ll_loops = 1 
END IF 


//Read the OLE stream, starting at the requested position 
ll_newpos = li_startat 
FOR ll_i = 1 to ll_loops 
    lole_stream.Seek (ll_newpos) 
    ll_rc = lole_stream.Read(lblob_temp, ll_chunk) 
    IF ll_i = 1 THEN 
     ablb_dataout = lblob_temp 
    ELSE 
      ablb_dataout = ablb_dataout + lblob_temp 
    END IF 
    ll_newpos = ll_newpos + ll_chunk 
NEXT 

此時你有一個位圖數據

不過,我一直在與儲存由MS數據塗料斑點。我們最近發現的是,新版本的MS Paint以WMF格式存儲數據而不是BMP。我們確實在這種情況下,什麼是認準OlePres000存儲,而不是Ole10Native存儲,然後再啓動40個字符到該存儲,而不是4

+0

驚人!你從哪裏獲得所有這些細節?你是否按照這個或如何遵循任何文件? :) – somnath

+0

關於一般使用OLEStreams和OLEStore的一點是來自Sybase文檔。其餘的是直接檢查複合文件,找出它們的結構,然後根據需要解析它們。 –