CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: BITMAP

  1. #1
    Join Date
    May 1999
    Posts
    9

    BITMAP

    How do I read a OLE field(Picture under SQL) and display it in a control?
    I need to read a picture stored in a database (SQL in my case).
    and how do I write a picture to a database?
    please send me some pieces of code

    R.F.L.

  2. #2
    Join Date
    Apr 1999
    Posts
    19

    Re: BITMAP

    To put a bitmap file in to a database,first create a byte array,copy file in to that array,and then write it in database as a long binary record.

    Here is some code,I hope it is helpful.
    below m_rSet_l is a object of CDaoRecordSet,
    filename can be any file,include bitmap :-)
    But code below has a problem,If you only call this function once in a time,it goes ok,but
    if you call it twice or more in a time,a error occours :-(((,can you tell me why ?

    extern "C" BOOL WINAPI PawnImg(char* u_id,
    char* filename)
    { CString ID;
    ID.Format("[L_PHOTO].[LESSEE_ID]='%s'",u_id);
    if(!m_rSet_l.IsOpen()) m_rSet_l.Open();
    if(m_rSet_l.Find(AFX_DAO_FIRST,ID)){
    m_rSet_l.Close();
    CString ID_message;
    // ID_message="There has no "+ID+" in this Database";
    ID_message="There has already has a ID "+ID+"in this database,so change another";
    AfxMessageBox(ID_message);
    return FALSE;
    }
    // m_rSet_l.Edit();

    m_rSet_l.AddNew();
    m_rSet_l.SetFieldValue("[LESSEE_ID]",u_id);

    FILE* f=fopen(filename,"rb");
    fseek(f,0,SEEK_END);
    unsigned long len=ftell(f);
    if(len>GlobalSize(m_rSet_l.m_PIC.m_hData))
    m_rSet_l.m_PIC.m_hData=GlobalAlloc(0,len);
    char* p=(char*)GlobalLock(m_rSet_l.m_PIC.m_hData);
    fseek(f,0,SEEK_SET);
    fread(p,1,len,f);
    fclose(f);
    GlobalUnlock(p);
    m_rSet_l.m_PIC.m_dwDataLength=len;
    m_rSet_l.SetFieldDirty(&m_rSet_l.m_PIC);
    m_rSet_l.SetFieldNull(&m_rSet_l.m_PIC,FALSE);
    m_rSet_l.Update();
    ::GlobalFree(m_rSet_l.m_PIC.m_hData);
    m_rSet_l.Close();
    return TRUE;
    }



    regards

    brett


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured