Convert Byte array into bitmap

I am making a Video file Player.

In this player i am reading 1 block of bytes and convert that block in bitmap using,

Dim bmp1 As Image = CType(Bitmap.FromStream(New MemoryStream(buffer_byte, start_position, stop_position)), Image)

and then displaying that image in picturebox. I have to display 30 images in 1 second.

but the Above method takes much CPU usage. so how can i reduce it

One thing I came to know is that i have to use DIRECTX or any other thing for use the GPU(Graphical processing Unit) instead of CPU. but i don't know much about that.




Answer this question

Convert Byte array into bitmap

  • cb2005uk

    Thanks Dear, but at the recording time i am getting images one by one. and i am storing that image in one file. that is now my recording file with particular delimeter between two images.

    Now i want to play that file so from the delimeter i can distiguish 2 images and get the bytes for 1 image and convert that into bitmap.

    So i cant use the standard video format. coz my recording format is fixed.

    But if it is possible to store the images at recording time into that standard format like MPEG or AVI than can u please provede help for convert the images into that standard format at recording time.



  • WIL PANNELL

    ya its ok, i tried that thing also but it can't make much difference in CPU usage. so i have to use GPU for processing of that conversion. so if u have any idea abt. directx or any other method so kindly reply me.

  • learn25

    You need a "video codec", a complicated chunk of software that can compress a video stream to a file and decompress it without taking a lot of CPU cycles. Rather than inventing the wheel, you might consider using one of the many open source projects.


  • Helder Santos

    You don't need a GPU; but you do need good high-performance code, or you need to use an off-the-shelp video file format, or you need very small bitmaps, and very modest expectations. If your quality bar is high, you'll have real problems if you try to re-invent the wheel. There are signficant challenges with delivering high-quality high-frame rate video on a windows platform. And 30fps is definitely a high frame rate by Windows standards. 15fps is pretty easy to do; 30fps is much harder, because you'll have to deal with issue like page-flipping. My advice: render it to a standard video format if you really want to do 30fps.

    My guess for why that code might be slow: an unwise choice of bitmap format, or a mismatch between bitmap format, and the format of the requested image, or between the format of the requested image and the screen output deivce. If the bitmap format doesn't map more or less bit-for-bit to your screen format, you're not going to render terribly efficiently. And if the bitmap is scaled at all... well... Don't do that. And it better be pretty small. High-quality video codecs would typically render to an in-video-card directx surface directly rather than going through an intermediate bitmap format, and would have separate code to handle decoding to each of a wide variety of video buffer formats.  And even then, you're going to be challenged to do 30fps.

    (I'm thinking go for a pre-encoded video stream. You've got a long road ahead of you going this way, if you *really* want to do 30 FPS with a high quality bar. There's a reason for those heavyweight video stream formats like MPG, AVI, Quicktime &c, and there's a reason why we use APIs like DirectShow to render video; and a reason why we have architected hardware support for video decoding).

     

     

     

     


  • Convert Byte array into bitmap