How to display an image?

  • Thread starter Thread starter Dean L. Howen
  • Start date Start date
D

Dean L. Howen

I create my own file format that could content many image files (jpg, ico,
....) . I can get the data of each image, and I want to display it on the
form. How can?
I've tried to create a file with the image data I want to show and open it
with that file name. No problem about this way. But I don't think it a good
way
Could anybody help me with another solution?
 
Hi Dean,
Create a stream for each image and pass that stream to the Bitmap class'
constructor. I don't know your file format, but if you can't use the
original file stream you probably should create a memory stream then
transfer the image bytes form the file and pass that stream to the Bitmap's
constructor.
 
Dear Stoitcho Goutsev,
Could I ask one more question?
Q: How could we limite a [stream] just read specific scale in the file
before passing stream to [Bitmap]? As you know, I try to save a "image file"
my file format, so if I pass the stream with no limited, the [Bitmap] could
not read image useful infomation.

For example my file format:

/////////////////////////////////////////
0-255 : Image_name
256-264 : Image_size
265..n : Image_file
/////////////////////////////////////////
(n = 265 + Image_size)

The Bitmap just should read the stream from 265 to n byte. How could we do
that?

Thanks
 
Hi Dean,

I haven't tested, but I'm pretty sure if you give the Bitmap construcotr a
stream with its pointer set to the 265th byte the bitmap will start reading
form there and will read as many bytes as it needs.
If you read your info part the pointer would be on the right position. If it
is not look at Stream.Seek method.


--
HTH
Stoitcho Goutsev (100) [C# MVP]
Dean L. Howen said:
Dear Stoitcho Goutsev,
Could I ask one more question?
Q: How could we limite a [stream] just read specific scale in the file
before passing stream to [Bitmap]? As you know, I try to save a "image
file"
my file format, so if I pass the stream with no limited, the [Bitmap]
could
not read image useful infomation.

For example my file format:

/////////////////////////////////////////
0-255 : Image_name
256-264 : Image_size
265..n : Image_file
/////////////////////////////////////////
(n = 265 + Image_size)

The Bitmap just should read the stream from 265 to n byte. How could we do
that?

Thanks

-------------------------------------------------------
Stoitcho Goutsev (100) said:
Hi Dean,
Create a stream for each image and pass that stream to the Bitmap class'
constructor. I don't know your file format, but if you can't use the
original file stream you probably should create a memory stream then
transfer the image bytes form the file and pass that stream to the Bitmap's
constructor.
 
Dear Stoitcho Goutsev,
it seems not work.
I try to append the existing image file with some bytes, it still works, but
not if I add some byte in the header although I have seek to the right
position

---------------------------------------------------------

Stoitcho Goutsev (100) said:
Hi Dean,

I haven't tested, but I'm pretty sure if you give the Bitmap construcotr a
stream with its pointer set to the 265th byte the bitmap will start reading
form there and will read as many bytes as it needs.
If you read your info part the pointer would be on the right position. If it
is not look at Stream.Seek method.


--
HTH
Stoitcho Goutsev (100) [C# MVP]
Dean L. Howen said:
Dear Stoitcho Goutsev,
Could I ask one more question?
Q: How could we limite a [stream] just read specific scale in the file
before passing stream to [Bitmap]? As you know, I try to save a "image
file"
my file format, so if I pass the stream with no limited, the [Bitmap]
could
not read image useful infomation.

For example my file format:

/////////////////////////////////////////
0-255 : Image_name
256-264 : Image_size
265..n : Image_file
/////////////////////////////////////////
(n = 265 + Image_size)

The Bitmap just should read the stream from 265 to n byte. How could we do
that?

Thanks

-------------------------------------------------------
Stoitcho Goutsev (100) said:
Hi Dean,
Create a stream for each image and pass that stream to the Bitmap class'
constructor. I don't know your file format, but if you can't use the
original file stream you probably should create a memory stream then
transfer the image bytes form the file and pass that stream to the Bitmap's
constructor.


I create my own file format that could content many image files (jpg, ico,
...) . I can get the data of each image, and I want to display it on
the
form. How can?
I've tried to create a file with the image data I want to show and
open
it
with that file name. No problem about this way. But I don't think it a
good
way
Could anybody help me with another solution?
 
Back
Top