Click here to Skip to main content
15,905,148 members
Home / Discussions / C#
   

C#

 
AnswerRe: Removing a " from a string Pin
Thomas Stockwell16-Feb-07 16:16
professionalThomas Stockwell16-Feb-07 16:16 
GeneralRe: Removing a " from a string Pin
sharpiesharpie17-Feb-07 1:34
sharpiesharpie17-Feb-07 1:34 
Questionhow to implement payflopro_recurringbilling through pfpro_dotnet_sdk_RC2_v1.1(verisign sdk) in c# Pin
shankhan bhandari16-Feb-07 11:33
shankhan bhandari16-Feb-07 11:33 
AnswerRe: how to implement payflopro_recurringbilling through pfpro_dotnet_sdk_RC2_v1.1(verisign sdk) in c# Pin
Wayne Phipps17-Feb-07 3:23
Wayne Phipps17-Feb-07 3:23 
QuestionProblem: vista will not sent a WM_ message [modified] Pin
michele_cv16-Feb-07 10:37
michele_cv16-Feb-07 10:37 
Questiongetting each byte of the pixel Pin
samreengr816-Feb-07 9:47
samreengr816-Feb-07 9:47 
AnswerRe: getting each byte of the pixel Pin
Christian Graus16-Feb-07 10:00
protectorChristian Graus16-Feb-07 10:00 
AnswerRe: getting each byte of the pixel Pin
Wayne Phipps17-Feb-07 4:29
Wayne Phipps17-Feb-07 4:29 
How about using serialisation? You could even use this to store practiaclly any object into a database.

Try this:
1) Create a new windows form app
2) Add to the form 2x picture boxes, one named source, the other dest
3) Add a new button named serialise
4) Set the background image of the picturebox named source to whatever you want (for testing, do this using the designer)
5) Add a handler to the buttons click event (this normally happens automatically if you double click the button in the designer)
6) Add using System.Runtime.Serialization.Formatters.Binary; declaration to your class
7) Paste the following code:
void SerialiseClick(object sender, EventArgs e)
{
    //serialise the background image of the source
    byte[] byteArray = Serialise( source.BackgroundImage );
    //deserialise the background image into the dest
    dest.BackgroundImage = (System.Drawing.Image)Deserialise(byteArray);
}

public static byte[] Serialise( object obj )
{
    //instanciate a new memory stream
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    //instanciate a new BinaryFormatter
    BinaryFormatter bf = new BinaryFormatter();
    //serialise the object into the memory stream
    bf.Serialize( ms, obj );
    //return the memory stream as a byte array
    return ms.ToArray();
}

public static object Deserialise( byte[] obj )
{
    //read the object into a memory stream
    System.IO.MemoryStream ms = new System.IO.MemoryStream( obj );
    //instanciate a binary formatter
    BinaryFormatter bf = new BinaryFormatter();
    //return the deserialised byte array as an object
    return bf.Deserialize(ms) ;
}


There is also Image.FromStream method which could be used instead and probably other ways of achieving a similar result.

Feel free to download the sample code I wrote from here: http://www.box.net/public/14kiat6na7

I love serialisation


Regards

Wayne Phipps
____________

Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog

QuestionDraging a line Pin
CodeItWell16-Feb-07 9:39
CodeItWell16-Feb-07 9:39 
AnswerRe: Draging a line Pin
Christian Graus16-Feb-07 10:00
protectorChristian Graus16-Feb-07 10:00 
AnswerRe: Draging a line Pin
MoustafaS16-Feb-07 10:23
MoustafaS16-Feb-07 10:23 
QuestionDevice Volume Monitor :: Issue On Insertion of CD? Pin
Matt U.16-Feb-07 9:32
Matt U.16-Feb-07 9:32 
QuestionSaving text? Pin
alostdruid16-Feb-07 9:16
alostdruid16-Feb-07 9:16 
AnswerRe: Saving text? Pin
MoustafaS16-Feb-07 10:27
MoustafaS16-Feb-07 10:27 
GeneralRe: Saving text? Pin
alostdruid16-Feb-07 11:51
alostdruid16-Feb-07 11:51 
GeneralRe: Saving text? Pin
MoustafaS16-Feb-07 12:09
MoustafaS16-Feb-07 12:09 
QuestionDataGridView - Adding new row Pin
Aleksandar Smudja16-Feb-07 9:11
Aleksandar Smudja16-Feb-07 9:11 
AnswerRe: DataGridView - Adding new row Pin
MoustafaS16-Feb-07 10:33
MoustafaS16-Feb-07 10:33 
GeneralRe: DataGridView - Adding new row Pin
Aleksandar Smudja16-Feb-07 11:17
Aleksandar Smudja16-Feb-07 11:17 
QuestionChild MDI problem with Events [modified] Pin
ross.anderson16-Feb-07 9:07
ross.anderson16-Feb-07 9:07 
QuestionStringBuilder vs. String Pin
yesufollower16-Feb-07 6:12
yesufollower16-Feb-07 6:12 
AnswerRe: StringBuilder vs. String Pin
Thomas Stockwell16-Feb-07 6:16
professionalThomas Stockwell16-Feb-07 6:16 
AnswerRe: StringBuilder vs. String Pin
tgrt16-Feb-07 7:05
tgrt16-Feb-07 7:05 
AnswerRe: StringBuilder vs. String Pin
Marcus J. Smith16-Feb-07 8:27
professionalMarcus J. Smith16-Feb-07 8:27 
AnswerRe: StringBuilder vs. String Pin
Luc Pattyn16-Feb-07 9:39
sitebuilderLuc Pattyn16-Feb-07 9:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.