|
-
Apr 7th, 2003, 01:42 PM
#1
Thread Starter
New Member
strange problem (streams and bitmaps)
I load a bitmap, put it into an array of bytes...i alter some values (in this case i put al the values starting from 13879 to 50000 on zero(black)).
_______Dim i As Integer
_______Dim mfs As FileStream
_______mfs = New FileStream("WW" & 1 & ".bmp", FileMode.Open)
_______Dim myarray(CInt(mfs.Length) - 1) As Byte
_______Dim mms As New MemoryStream()
_______mfs.Read(myarray, 0, mfs.Length)
_______mfs.Close()
_______For i = 13879 To 50000 Step 1
___________myarray(i) = 0
_______Next
I write my array to a memorystream cause that way i can put it into the picture box
_______mms.Write(myarray, 0, myarray.Length)
_______pBox.Image = System.Drawing.Bitmap.FromStream(mms)
Now here is the problem. When i draw the pbox, all elements behind 13879 are set to zero. When i put watches on it then the mms(memorystream) and array are filled up correctly even after drawing the pbox. What's wrong with it?? It should only draw black till 50000.
I used setpixel, put it is way to slow so that's not a noption anymore.
ty...
Khumbu
-
Apr 7th, 2003, 03:06 PM
#2
Frenzied Member
It seems that the order of byte are not top to bottom as you might excpect. To add to your surprise it also seems that zero (0) will not always represent black. I can send you a picture that putting bytes to zero will lead to 'White' and 255 to Black. I dont know why.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 8th, 2003, 07:00 AM
#3
Thread Starter
New Member
I know that, but i just wan't to write a function that change a certain line in a bitmap in a certain color. I studied a bitmap and knows how it looks like.
The code above should only change the bytes i put to 0, not the ones behind the, my bitmap has more than 200000 pixels long.
-
Apr 8th, 2003, 07:09 AM
#4
Frenzied Member
I guess each pixel wont reflect one byte, does it? so you may have to change a group of byte to change one pixel attribs.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 8th, 2003, 07:14 AM
#5
Thread Starter
New Member
Correct, the number of bytes to change depends on your bitmap format, that's in the header of your bitmapfile. I work with a bitmap where eacht color is 8 bit, so 1 byte but that's not really important in this case.
The problem is
"Now here is the problem. When i draw the pbox, all elements behind 13879 are set to zero. When i put watches on it then the mms(memorystream) and array are filled up correctly even after drawing the pbox. What's wrong with it?? It should only draw black till 50000. " while my bitmap is much longer. Is this a bug?
at the moment i am testing some stuff to locate the problem or do it another way, i'll keep you guys updated
Last edited by Khumbu; Apr 8th, 2003 at 07:20 AM.
-
Apr 8th, 2003, 07:49 AM
#6
Thread Starter
New Member
haven't solved my problem but took a look at setpixel and tried this
Dim i As Integer
Dim j As Integer
Dim one As Integer
Dim two As Integer
one = (Now.Second * 1000) + Now.Millisecond
For i = 50 To 200
For j = 0 To 639
bitmaptest.SetPixel(j, i, Color.White)
Next
Next
pBox.Image = bitmaptest
two = (Now.Second * 1000) + Now.Millisecond
txtBox.AppendText("Finished: " & (two - one) & " ms" & vbLf)
output: Finished: 266 ms
this peace of code is fast, but not fast enough, any ideas to make it faster?
ty
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|