Results 1 to 6 of 6

Thread: strange problem (streams and bitmaps)

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    8

    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

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    8
    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.

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    8
    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    8
    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
  •  



Click Here to Expand Forum to Full Width