Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wish to load images from database into memory and then render it to an appropriate section of a window?

The reason being that, I do not want copies of the images to be available as file on the system because they are mostly sensitive image that need to be secured and kept away from unauthourised person.

Is there a way I can render the image as mentioned above?

If no, which is the best way to achieve this kind of image security that I desire?



P.S.
The images are to be loaded from database.

NEW ADDITION:

below is a relevant section of code ahowing how I render image. I wish to take originalGruf's suggestion. I wish to load an Image file to memory decrypt it in memory and theen render to window. Is it possible to do it with a variation of the code below or must I use a completely different code.

Btw. How does one convert a file int a stream.

C++
if(LoadOptional(szFilePath,sizeof(szFilePath),iStudentID,pStudEdit->m_iClassID))
   {
       if(lstrlen(szFilePath))
       {
           CFile *pFile = NULL;
           try
           {
              pFile = new CFile(szFilePath,CFile::modeRead | CFile::shareDenyNone);
              m_stFilePath = szFilePath;

              //Draw Image
               Image image(m_stFilePath);
               Graphics graphics(dc);
               graphics.DrawImage(&image,m_rcImage.left,m_rcImage.top,m_rcImage.Width(),m_rcImage.Height());
           }
           catch (CFileException* pEx)
           {
              pEx->ReportError();
              pEx->Delete();
           }
           catch(CMemoryException* pEx)
           {
              pEx->ReportError();
              pEx->Delete();
              AfxAbort();
           }
           if(pFile != NULL)
           {
              pFile->Close();
              delete pFile;
           }
       }



Does this make sense?
CFile *pFile = NULL;

pFile = new CFile(m_stFilePath,CFile::modeRead | CFile::shareDenyNone);
DWORD dwFileSize = pFile->GetLength();
unsigned char *pBLOB = new unsigned char [m_dwFileSize];
if(pFile->Read(pBLOB,m_dwFileSize))

 Image image((const char *)pBLOB);
 Graphics graphics(dc);
     graphics.DrawImage(&image,m_rcImage.left,m_rcImage.top,m_rcImage.Width(),m_rcImage.Height());
Posted
Updated 21-Jun-15 23:33pm
v7

The source of an image is irrelevant: if you have the code to display an image from a file, all you have to do is replace the file stream with your memory data - presumably you have already loaded the file stream at some point into order to get it into the DB to start with?

But...if you don't want people to look at your picture collection, then storing it in a database is not the most secure means in the world. You might want to consider leaving them on disk as files, but using some form of encryption to secure the content instead.
 
Share this answer
 
Comments
Gbenbam 22-Jun-15 3:43am    
Problem is that I only know how to render image from file using :

Graphics graphics(dc);

Image image(pszFilename);

graphics.DrawImage(e.t.c) .

I know Image has a constructor that accepts streams but inspection shows that the stream in question is not ios::ifstream.

Perhaps the question could be:

How can one convert a file into a stream in memory and the render it.( I don't know if this makes sense. Do you think it does?)
OriginalGriff 22-Jun-15 3:54am    
Just what exactly are you using? Your question is tagged MFC, but Image is not an MFC class I am aware of - CImage is, but Image isn't.
Can you point me at the MSDN documentation for exactly what you are using?
Gbenbam 22-Jun-15 4:00am    
Image is a c++ class. I found the example in MSDN. I don't know if it is an MFC class. I'll locate the link to that MSDN page and post it here. Just a minute,please.
Gbenbam 22-Jun-15 4:04am    
Here you are:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms536051%28v=vs.85%29.aspx
OriginalGriff 22-Jun-15 4:13am    
Right: that Image has an overload which accepts a IStream (as you said):
https://msdn.microsoft.com/en-us/library/windows/desktop/ms535410(v=vs.85).aspx
And IStream can be constructed and a stream of bytes written to it:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa380014(v=vs.85).aspx

So read your byte data from the DB (you know how to do that, I'm sure - you wrote it there!), create an IStream, write the data to it, and use the stream to create the Image. Sorted! :laugh:
See https://msdn.microsoft.com/en-us/library/windows/desktop/aa378980(v=vs.85).aspx[^]. You use this to create a stream from a memory image. You can then use Image::FromStream to create an image that can be rendered on a DC.
 
Share this answer
 
Comments
Gbenbam 22-Jun-15 6:11am    
Thanks. I very grateful. Its been quite a while. How has your day been?

It seems this is even better:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773831%28v=vs.85%29.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900