Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Basically i have an image file(jpeg) and a text file .
Is there a way to "merge"this 2 things into a new file type and able to open it up?

I know how to encrypt a text file but had no idea on image file.
Posted

Yes, you can do it, but it might be best to use some existing code.
The problem is changes: If you change either the text or the image, you have to re-write the other one as well.
If you are dealing only with a file which contains one image, and one set of text, then it's not a major problem: Make a Serialisable class and let the framework handle the business.
If it gets much more complex (N files, or variable numbers of images / texts) then I would consider a database instead.
There is SqlCE which is pretty simple to use in a single user environment, and doesn't require any database engine installed with your app.
 
Share this answer
 
Comments
tuolesi 14-Nov-10 7:14am    
Thx for ur guides.
Since i m dealing with one set of image and txt only.I think it will be an easier job for me.
Hi,

you can convert the bitmap to a string, store it in a file and then you can read it back as string and convert it to an image.
You need to make sure you always know which part of your file is text and which part is an image. Well suited for this could be for example xml. For storing an bitmap to a string and back you can use:

public string ImageToBase64String( Image image, ImageFormat format )
{
   MemoryStream memory = new MemoryStream();
   image.Save( memory, format );
   string base64 = Convert.ToBase64String( memory.ToArray() );
   memory.Close();
   return base64;
}
public Image ImageFromBase64String( string base64 )
{
   MemoryStream memory = new MemoryStream( Convert.FromBase64String( base64 ) );
   Image result = Image.FromStream( memory );
   memory.Close();
   return result;
}
 
Share this answer
 
Comments
tuolesi 14-Nov-10 7:13am    
great,thx for ur help.
Is the imageformat limited to certain format only?

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