loading image to BitmapEx from 'array as byte'

Byak@

Active Member
Licensed User
how can i do it without saving image to file? i'm recive this image with NetUDP as bytes and place to array.but i must load this to BitmapEx object
 

agraham

Expert
Licensed User
Longtime User
Depends upon what format the data is in. If it is a bmp or jpg file sent as a stream of bytes then it is easiest to re-save it to a file and load it from there. If it is raw pixel RGB data then you could reassemle it into pixels and write it to a BitmapEx of the correct size using SetLockedPixel.
 

Byak@

Active Member
Licensed User
2Andrew
yes,it is a bitmap image (i'm get it from WebCam with your lib).
saving to file and then load-it is so slow,i'm need a fast method (i'm receive image every 300ms)
i'm found this method(draw from bytes) in Alpha.dll but this lib have a conflict with ImageLibEx (with name of object)
can you add new method to your lib?
 

agraham

Expert
Licensed User
Longtime User
yes,it is a bitmap image
:confused: That's obvious but you haven't said whether it is formatted or raw pixel data.

If you are on the desktop you could use GDI+Desktop instead of ImageLibEx. This does not have an Alpha object which I assume is what the conflict is.
 

Byak@

Active Member
Licensed User
ooops))
i have a new problem)))))how can i convert image(bitmap from bitmapex object) to bites(for send) without writing to file(amd reading with bin object).this method is slow,i'm need a fast method!
 

Byak@

Active Member
Licensed User
big thanks Andrew
 

Byak@

Active Member
Licensed User
i'm try send photo with network dll but...
please correct me.in my sample received image is broken
 

Attachments

  • fire.JPG
    fire.JPG
    3.9 KB · Views: 209
  • NetDemo_bitmap.sbp
    8.7 KB · Views: 253

Byak@

Active Member
Licensed User
UP.
any ideas? it is for my diplom and it is very important
 
Last edited:

agraham

Expert
Licensed User
Longtime User
The problem is most probably the way you are receiving the data. Your code is expecting it to all arrive at once and it won't. TCP/IP is a stream protocol not a block protocol so not all the data is guaranteed to arrive at once. You are trying to receive 49Kbytes which will need at least 32 Ethernet packets. You need to buffer up the received data on successive reads until you have the correct number and only then try to convert the bitmap. The number you give to ReadBytes is the maximum number of bytes that it will read but if the stream is empty because not all the data has arrived it will return less. You can see the number of bytes actually read from the return value of ReadBytes, use this to determine where in the buffer to save the data from the next read.
 
Top