R
Ryan
Hi All,
I know this topic is getting a bit old now by the number of blog
postings I've been reading and information in google groups but I'm
having bitmap trouble. It's a simple survey application which displays a
picture to a user and allows them to take another one if the status of
the item in question has deteriorated. The code runs fine the first time
then fails on the second run through at the point it displays the picture.
If anybody can give me some clues as to where my code is going wrong I
would applicate it. Everything else works apart from this.
Thank you
Ryan
void DisplayCameraAnswer(){
this.CameraImage = new PictureBox();
/* Removed - Code to position PictureBox */
this.Controls.Add(this.CameraImage);
this.CameraData = new MemoryStream();
this.reportWriter.ReadImageData("Image01", ref this.CameraData);
if (CameraData.Length > 0) {
this.CameraData.Position = 0;
// Exception raised here.
this.CameraImage.Image = new Bitmap(this.CameraData);
}
}
void QuestionCleanup(){
if(CameraData != null){
this.CameraData.Close();
this.CameraData = null;
}
if(CameraImage!= null){
this.Controls.Remove(this.CameraImage);
if(this.CameraImage.Image != null){
this.CameraImage.Image.Dispose();
this.CameraImage.Image = null;
}
this.CameraImage.Dispose();
this.CameraImage = null;
}
}
/* *** reportWriter ReadImageData Function *** */
void ReadImageData(string FieldName, ref MemoryStream ImageData){
ImageData.SetLength(0);
FieldIndex = this.rsImageData.GetOrdinal(FieldName);
if (!this.rsImageData.IsDBNull(FieldIndex)) {
// Get the size for the data in the database
DataLength = (Int32)this.rsImageData.GetBytes(FieldIndex, 0,
null, 0, 0);
// Allocate the byte[] buffer
byte[] DataBuff = new byte[DataLength];
// Read the data from the database
this.rsImageData.GetBytes(FieldIndex, 0, DataBuff, 0, DataLength);
// Write it to the memory stream
ImageData.Write(DataBuff, 0, DataBuff.Length);
}
}
I know this topic is getting a bit old now by the number of blog
postings I've been reading and information in google groups but I'm
having bitmap trouble. It's a simple survey application which displays a
picture to a user and allows them to take another one if the status of
the item in question has deteriorated. The code runs fine the first time
then fails on the second run through at the point it displays the picture.
If anybody can give me some clues as to where my code is going wrong I
would applicate it. Everything else works apart from this.
Thank you
Ryan
void DisplayCameraAnswer(){
this.CameraImage = new PictureBox();
/* Removed - Code to position PictureBox */
this.Controls.Add(this.CameraImage);
this.CameraData = new MemoryStream();
this.reportWriter.ReadImageData("Image01", ref this.CameraData);
if (CameraData.Length > 0) {
this.CameraData.Position = 0;
// Exception raised here.
this.CameraImage.Image = new Bitmap(this.CameraData);
}
}
void QuestionCleanup(){
if(CameraData != null){
this.CameraData.Close();
this.CameraData = null;
}
if(CameraImage!= null){
this.Controls.Remove(this.CameraImage);
if(this.CameraImage.Image != null){
this.CameraImage.Image.Dispose();
this.CameraImage.Image = null;
}
this.CameraImage.Dispose();
this.CameraImage = null;
}
}
/* *** reportWriter ReadImageData Function *** */
void ReadImageData(string FieldName, ref MemoryStream ImageData){
ImageData.SetLength(0);
FieldIndex = this.rsImageData.GetOrdinal(FieldName);
if (!this.rsImageData.IsDBNull(FieldIndex)) {
// Get the size for the data in the database
DataLength = (Int32)this.rsImageData.GetBytes(FieldIndex, 0,
null, 0, 0);
// Allocate the byte[] buffer
byte[] DataBuff = new byte[DataLength];
// Read the data from the database
this.rsImageData.GetBytes(FieldIndex, 0, DataBuff, 0, DataLength);
// Write it to the memory stream
ImageData.Write(DataBuff, 0, DataBuff.Length);
}
}