Click here to Skip to main content
16,005,121 members
Home / Discussions / C#
   

C#

 
QuestionString.Replace with Escaped Characters Pin
Reanalyse20-Nov-05 15:11
Reanalyse20-Nov-05 15:11 
AnswerRe: String.Replace with Escaped Characters Pin
S. Senthil Kumar20-Nov-05 18:55
S. Senthil Kumar20-Nov-05 18:55 
QuestionDate Comparison Pin
tatchung20-Nov-05 15:07
tatchung20-Nov-05 15:07 
AnswerRe: Date Comparison Pin
Christian Graus20-Nov-05 15:43
protectorChristian Graus20-Nov-05 15:43 
GeneralRe: Date Comparison Pin
tatchung20-Nov-05 16:03
tatchung20-Nov-05 16:03 
QuestionHow to exact the tsk Pin
activesync20-Nov-05 13:53
activesync20-Nov-05 13:53 
QuestionNeed help with reading image from stream using GDI+ Pin
serguey_haftrige20-Nov-05 13:41
serguey_haftrige20-Nov-05 13:41 
AnswerRe: Need help with reading image from stream using GDI+ Pin
Curtis Schlak.20-Nov-05 14:26
Curtis Schlak.20-Nov-05 14:26 
If you would like to use your code above, here is my two cents:

Create the following class in your project. It wraps a FileStream that allows you to override the seeking ability.
public class HardFileStream : FileStream
{
  private bool hardPositionSet;

  public HardFileStream( string path )
    : base( path, FileMode.OpenOrCreate, FileAccess.ReadWrite ) {}

  public bool HasHardPositionSet
  {
    get
    {
      return hardPositionSet;
    }
  }

  // Sets the position of the file stream and prevents seeking to other positions.
  public void SetHardPosition( long pos )
  {
    base.Position = pos;
    hardPositionSet = true;
  }

  // Releases the hold on seeking.
  public void ReleaseHardPosition()
  {
    hardPositionSet = false;
  }

  public override long Position
  {
    get
    {
      return base.Position;
    }
    set
    {
      if( !hardPositionSet )
        base.Position = value;
    }
  }

  public override bool CanSeek
  {
    get
    {
      return !hardPositionSet;
    }
  }

  public override long Seek( long offset, SeekOrigin origin )
  {
    if( !hardPositionSet )
    {
      return base.Seek( offset, origin );
    }
    return 0;
  }
}


Now, change your code to the following:
HardFileStream fs = new HardFileStream( "test.dat" );
Image img;
img = Image.FromFile( "image1.jpg" );
img.Save(fs,ImageFormat.Jpeg);
img.Dispose();

long p2 = fs.Position;
img = Image.FromFile( "image2.jpg" );
img.Save( fs, ImageFormat.Jpeg );
img.Dispose();

fs.Position=0; //set the stream position to the start of image1
pictureBox1.Image = Image.FromStream(fs);
fs.SetHardPosition( p2 ); //set the stream position to the start of image2
pictureBox2.Image = Image.FromStream(fs);
fs.ReleaseHardPosition();


And, that should do it. My test project compiles and shows the two separate images in the two picture boxes.

"we must lose precision to make significant
      statements about complex systems."
              -deKorvin on uncertainty


-- modified at 23:11 Monday 21st November, 2005
GeneralRe: Need help with reading image from BUFFER using GDI+ Pin
serguey_haftrige22-Nov-05 15:49
serguey_haftrige22-Nov-05 15:49 
QuestionC# Process UseShellExecute query Pin
Kuira20-Nov-05 12:30
Kuira20-Nov-05 12:30 
AnswerRe: C# Process UseShellExecute query Pin
Xiangyang Liu 刘向阳20-Nov-05 13:37
Xiangyang Liu 刘向阳20-Nov-05 13:37 
QuestionHashtable - Get picked values Pin
Seraphin20-Nov-05 11:23
Seraphin20-Nov-05 11:23 
AnswerRe: Hashtable - Get picked values Pin
Christian Graus20-Nov-05 11:36
protectorChristian Graus20-Nov-05 11:36 
GeneralRe: Hashtable - Get picked values Pin
Seraphin20-Nov-05 11:51
Seraphin20-Nov-05 11:51 
GeneralRe: Hashtable - Get picked values Pin
Christian Graus20-Nov-05 11:53
protectorChristian Graus20-Nov-05 11:53 
GeneralRe: Hashtable - Get picked values Pin
Seraphin20-Nov-05 12:01
Seraphin20-Nov-05 12:01 
GeneralRe: Hashtable - Get picked values Pin
Christian Graus20-Nov-05 12:10
protectorChristian Graus20-Nov-05 12:10 
GeneralRe: Hashtable - Get picked values Pin
Seraphin20-Nov-05 12:17
Seraphin20-Nov-05 12:17 
AnswerRe: Hashtable - Get picked values Pin
Leslie Sanford20-Nov-05 13:16
Leslie Sanford20-Nov-05 13:16 
GeneralRe: Hashtable - Get picked values Pin
Seraphin20-Nov-05 14:24
Seraphin20-Nov-05 14:24 
GeneralRe: Hashtable - Get picked values Pin
Leslie Sanford20-Nov-05 17:28
Leslie Sanford20-Nov-05 17:28 
GeneralRe: Hashtable - Get picked values Pin
Seraphin21-Nov-05 4:16
Seraphin21-Nov-05 4:16 
QuestionHow can I reference from a string to an objectname? Pin
Slerp20-Nov-05 10:30
Slerp20-Nov-05 10:30 
AnswerRe: How can I reference from a string to an objectname? Pin
serguey_haftrige20-Nov-05 14:11
serguey_haftrige20-Nov-05 14:11 
AnswerRe: How can I reference from a string to an objectname? Pin
Curtis Schlak.20-Nov-05 14:45
Curtis Schlak.20-Nov-05 14:45 

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.