|
|
|
start date: Sun, 22 Jul 2007 15:35:40 -0400,
posted on: microsoft.public.dotnet.framework.drawing
back
| Thread Index |
|
1
active
|
|
2
Göran Andersson
|
|
3
active
|
|
4
Göran Andersson
|
|
5
active
|
|
6
Michael Phillips, Jr. 0.c0m
|
|
7
active
|
|
8
Michael Phillips, Jr. 0.c0m
|
|
9
active
|
Values in memorystream buffer confusing
See code below
mDifImage is 8-bit indexed
How can I calculate what value to set sz to?
I look at buffer expecting it to start with
BITMAPFILEHEADER 14 bytes
or
BITMAPINFOHEADER 40 bytes
but I see 13 bytes of mostly 2=digit values
followed by many 3-digit values.
What should I expect to see?
Also, to convert two bytes to a value is it
buffer(i) + 256*buffer(i+1)
or
buffer(i+1) +2568buffer(i)
thanks in advance
Dim sz As Integer = 444444
Dim buffer(sz) As Byte
Dim ms As New MemoryStream(buffer)
mGifImage.Save(ms, ImageFormat.Gif)
Date:Sun, 22 Jul 2007 15:35:40 -0400
Author:
|
Re: Values in memorystream buffer confusing
active wrote:
> See code below
>
> mDifImage is 8-bit indexed
>
> How can I calculate what value to set sz to?
You can't. Well, you could, but that would mean that you would have to
copy almost everything from the compression algorithm that creates the
file. You would basically do the compression
However, you don't need to know the size of the image before you create it.
> I look at buffer expecting it to start with
>
> BITMAPFILEHEADER 14 bytes
>
> or
>
> BITMAPINFOHEADER 40 bytes
>
> but I see 13 bytes of mostly 2=digit values
>
> followed by many 3-digit values.
>
> What should I expect to see?
You should expect the data to begin with the bytes:
0x47 0x49 0x46 0x38 0x37 0x61 ("GIF87a")
or
0x47 0x49 0x46 0x38 0x39 0x61 ("GIF89a")
> Also, to convert two bytes to a value is it
>
> buffer(i) + 256*buffer(i+1)
>
> or
>
> buffer(i+1) +2568buffer(i)
That depends on the file format. You have to check the specification of
the file format to see if it uses little-endian (Intel) format or
big-endian (Motorola) format.
> thanks in advance
>
> Dim sz As Integer = 444444
>
> Dim buffer(sz) As Byte
>
> Dim ms As New MemoryStream(buffer)
Don't create a buffer for a MemoryStream that you are going to write to.
Just use the parameterless constructor, and the MemoryStream will create
it's own buffer.
> mGifImage.Save(ms, ImageFormat.Gif)
--
Gran Andersson
_____
http://www.guffa.com
Date:Mon, 23 Jul 2007 10:44:59 +0200
Author:
|
Re: Values in memorystream buffer confusing
"Gran Andersson" wrote in message
news:%23aYPHXQzHHA.3916@TK2MSFTNGP02.phx.gbl...
> active wrote:
>> See code below
>>
>> mDifImage is 8-bit indexed
>>
>> How can I calculate what value to set sz to?
>
> You can't. Well, you could, but that would mean that you would have to
> copy almost everything from the compression algorithm that creates the
> file. You would basically do the compression
>
> However, you don't need to know the size of the image before you create
> it.
>
>> I look at buffer expecting it to start with
>>
>> BITMAPFILEHEADER 14 bytes
>>
>> or
>>
>> BITMAPINFOHEADER 40 bytes
>>
>> but I see 13 bytes of mostly 2=digit values
>>
>> followed by many 3-digit values.
>>
>> What should I expect to see?
>
> You should expect the data to begin with the bytes:
>
> 0x47 0x49 0x46 0x38 0x37 0x61 ("GIF87a")
>
> or
>
> 0x47 0x49 0x46 0x38 0x39 0x61 ("GIF89a")
>
>> Also, to convert two bytes to a value is it
>>
>> buffer(i) + 256*buffer(i+1)
>>
>> or
>>
>> buffer(i+1) +2568buffer(i)
>
> That depends on the file format. You have to check the specification of
> the file format to see if it uses little-endian (Intel) format or
> big-endian (Motorola) format.
I can look uo the meaning of these formats.
But what I don't know is:
Can the file be either way depending on how it was written?
>
>> thanks in advance
>>
>> Dim sz As Integer = 444444
>>
>> Dim buffer(sz) As Byte
>>
>> Dim ms As New MemoryStream(buffer)
>
> Don't create a buffer for a MemoryStream that you are going to write to.
> Just use the parameterless constructor, and the MemoryStream will create
> it's own buffer.
And it will insure that it is big enough for whatever I read, which explains
you comment,
"you don't need to know the size of the image "
Is that correct?
Thanks
>
>> mGifImage.Save(ms, ImageFormat.Gif)
>
> --
> Gran Andersson
> _____
> http://www.guffa.com
Date:Mon, 23 Jul 2007 08:31:46 -0400
Author:
|
Re: Values in memorystream buffer confusing
> How can I calculate what value to set sz to?
1) If you have a BITMAPFILEHEADER, then the first two bytes represent the
bitmap's signature.
This signature is 'BM'. Read the first two bytes. If byte[0] = 'B' and
byte[1] = 'M ', then you have a BITMAPFILEHEADER.
Rewind the stream and then read the entire header of 14 bytes. The value of
sz will be 14.
2) If you have a BITMAPINFOHEADER instead of a BITMAPFILEHEADER, the first
Uint32 will be the size of the BITMAPINFOHEADER' s structure.
For your example, read the first Uint32. If the value that you read is 40,
then rewind the stream and read the entire 40 bytes of the BITMAPINFOHEADER.
The value of sz will be 40.
Once you have parsed the structures, you then can proceed to process the
rest of the stream.
" active" wrote in message
news:Og$u9dJzHHA.3940@TK2MSFTNGP05.phx.gbl...
> See code below
>
> mDifImage is 8-bit indexed
>
> How can I calculate what value to set sz to?
>
>
>
> I look at buffer expecting it to start with
>
> BITMAPFILEHEADER 14 bytes
>
> or
>
> BITMAPINFOHEADER 40 bytes
>
> but I see 13 bytes of mostly 2=digit values
>
> followed by many 3-digit values.
>
> What should I expect to see?
>
> Also, to convert two bytes to a value is it
>
> buffer(i) + 256*buffer(i+1)
>
> or
>
> buffer(i+1) +2568buffer(i)
>
> thanks in advance
>
> Dim sz As Integer = 444444
>
> Dim buffer(sz) As Byte
>
> Dim ms As New MemoryStream(buffer)
>
> mGifImage.Save(ms, ImageFormat.Gif)
>
>
Date:Mon, 23 Jul 2007 09:40:26 -0400
Author:
|
Re: Values in memorystream buffer confusing
mGifImage is a bitmap 8-bit indexed
I would have guessed that its length would be one of
the properties but if it is I didn't recognoze it.
So I used 444444.
Dim sz As Integer = 444444
Dim buffer(sz) As Byte
Dim ms As New MemoryStream(buffer)
mGifImage.Save(ms, ImageFormat.Gif)
'I believe the last writes into buffer. Right?
buffer length = 444445 and contains
0 71
1 73
2 70
3 56
4 57
....
I expected to see what you described below!
"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:Oh1CP8SzHHA.312@TK2MSFTNGP04.phx.gbl...
>> How can I calculate what value to set sz to?
>
> 1) If you have a BITMAPFILEHEADER, then the first two bytes represent the
> bitmap's signature.
> This signature is 'BM'. Read the first two bytes. If byte[0] = 'B' and
> byte[1] = 'M ', then you have a BITMAPFILEHEADER.
> Rewind the stream and then read the entire header of 14 bytes. The value
> of sz will be 14.
>
> 2) If you have a BITMAPINFOHEADER instead of a BITMAPFILEHEADER, the first
> Uint32 will be the size of the BITMAPINFOHEADER' s structure.
> For your example, read the first Uint32. If the value that you read is
> 40, then rewind the stream and read the entire 40 bytes of the
> BITMAPINFOHEADER.
> The value of sz will be 40.
>
> Once you have parsed the structures, you then can proceed to process the
> rest of the stream.
>
>
> " active" wrote in message
> news:Og$u9dJzHHA.3940@TK2MSFTNGP05.phx.gbl...
>> See code below
>>
>> mDifImage is 8-bit indexed
>>
>> How can I calculate what value to set sz to?
>>
>>
>>
>> I look at buffer expecting it to start with
>>
>> BITMAPFILEHEADER 14 bytes
>>
>> or
>>
>> BITMAPINFOHEADER 40 bytes
>>
>> but I see 13 bytes of mostly 2=digit values
>>
>> followed by many 3-digit values.
>>
>> What should I expect to see?
>>
>> Also, to convert two bytes to a value is it
>>
>> buffer(i) + 256*buffer(i+1)
>>
>> or
>>
>> buffer(i+1) +2568buffer(i)
>>
>> thanks in advance
>>
>> Dim sz As Integer = 444444
>>
>> Dim buffer(sz) As Byte
>>
>> Dim ms As New MemoryStream(buffer)
>>
>> mGifImage.Save(ms, ImageFormat.Gif)
>>
>>
>
>
Date:Mon, 23 Jul 2007 11:54:31 -0400
Author:
|
Re: Values in memorystream buffer confusing
The signature bytes of image are predicated on the image.
For a bitmap it is 0x42, 0x4D hex or 66, 77 decimal <-----('B','M')
For a gif the signature is GIF87 or GIF89a
GIF89a:
0x47,0x49, 0x46, 0x38,0x39,0x61 hex
71, 73, 70, 56,57,97 decimal
> 0 71
>
> 1 73
>
> 2 70
>
> 3 56
>
> 4 57
The above is part of the signature for a GIF89a file
Date:Mon, 23 Jul 2007 12:33:38 -0400
Author:
|
Re: Values in memorystream buffer confusing
thanks
"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:eH338cUzHHA.4712@TK2MSFTNGP04.phx.gbl...
> The signature bytes of image are predicated on the image.
>
> For a bitmap it is 0x42, 0x4D hex or 66, 77 decimal <-----('B','M')
>
> For a gif the signature is GIF87 or GIF89a
> GIF89a:
> 0x47,0x49, 0x46, 0x38,0x39,0x61 hex
> 71, 73, 70, 56,57,97 decimal
>
>> 0 71
>>
>> 1 73
>>
>> 2 70
>>
>> 3 56
>>
>> 4 57
>
> The above is part of the signature for a GIF89a file
>
>
Date:Mon, 23 Jul 2007 21:42:08 -0400
Author:
|
Re: Values in memorystream buffer confusing
active wrote:
>>> Also, to convert two bytes to a value is it
>>>
>>> buffer(i) + 256*buffer(i+1)
>>>
>>> or
>>>
>>> buffer(i+1) +2568buffer(i)
>> That depends on the file format. You have to check the specification of
>> the file format to see if it uses little-endian (Intel) format or
>> big-endian (Motorola) format.
>
>
> I can look uo the meaning of these formats.
> But what I don't know is:
> Can the file be either way depending on how it was written?
Some image formats can be either way. As I remember it, the GIF format
always uses the same.
>>> thanks in advance
>>>
>>> Dim sz As Integer = 444444
>>>
>>> Dim buffer(sz) As Byte
>>>
>>> Dim ms As New MemoryStream(buffer)
>> Don't create a buffer for a MemoryStream that you are going to write to.
>> Just use the parameterless constructor, and the MemoryStream will create
>> it's own buffer.
>
>
> And it will insure that it is big enough for whatever I read, which explains
> you comment,
> "you don't need to know the size of the image "
>
> Is that correct?
Right.
--
Gran Andersson
_____
http://www.guffa.com
Date:Wed, 25 Jul 2007 08:59:23 +0200
Author:
|
Re: Values in memorystream buffer confusing
that's true. I did find a table on the Internet that showed the usage of
many files.
thanks
"Gran Andersson" wrote in message
news:OeFdglozHHA.5980@TK2MSFTNGP04.phx.gbl...
> active wrote:
>>>> Also, to convert two bytes to a value is it
>>>>
>>>> buffer(i) + 256*buffer(i+1)
>>>>
>>>> or
>>>>
>>>> buffer(i+1) +2568buffer(i)
>>> That depends on the file format. You have to check the specification of
>>> the file format to see if it uses little-endian (Intel) format or
>>> big-endian (Motorola) format.
>>
>>
>> I can look uo the meaning of these formats.
>> But what I don't know is:
>> Can the file be either way depending on how it was written?
>
> Some image formats can be either way. As I remember it, the GIF format
> always uses the same.
>
>>>> thanks in advance
>>>>
>>>> Dim sz As Integer = 444444
>>>>
>>>> Dim buffer(sz) As Byte
>>>>
>>>> Dim ms As New MemoryStream(buffer)
>>> Don't create a buffer for a MemoryStream that you are going to write to.
>>> Just use the parameterless constructor, and the MemoryStream will create
>>> it's own buffer.
>>
>>
>> And it will insure that it is big enough for whatever I read, which
>> explains you comment,
>> "you don't need to know the size of the image "
>>
>> Is that correct?
>
> Right.
>
> --
> Gran Andersson
> _____
> http://www.guffa.com
Date:Wed, 25 Jul 2007 08:54:30 -0400
Author:
|
|
|