[OT] jak na rychle vykreslovani bitmap, Win, C#

Jaroslav Buchta jaroslav.buchta na hascomp.cz
Pondělí Leden 19 19:43:50 CET 2015


Jakym smerem se vydat? Potrebuju v podstate rychle posouvat radky v okne 
a pridavat nove radky, je to pro vizualizaci dat z radkove kamery.
Tak 1000 radku/s po 512 px by bylo ideal. Uvedeny kod zvladne tak 40 
(512x500 pixelu) takze to chce vice nez radove zlepseni vykonu.

Zatim jsem udelal tento hruby pokus a tudy cesta asi nevede (da se to 
urcite jeste optimalizovat ale je to v principu same kopirovani velkeho 
pole)

Existuje nejaka lepsi metoda, jak rychle periodicky zobrazovat v okne 
aktualni obraz ktery je jako pole pixelu? Ale zas univerzalni, aby to 
nebylo vazane na nejakou konkretni graf. kartu, cpu atp.

         private unsafe void backgroundWorker1_DoWork(object sender, 
DoWorkEventArgs e)
         {

             while (!bwFin)
             {

                 BitmapData bmd = bmp.LockBits(new Rectangle(0, 0, 
bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);

                 IntPtr ptr = bmd.Scan0;

                 int lnBytes = Math.Abs(bmd.Stride);
                 int bytes = lnBytes * bmp.Height;
                 if (rgbValues == null)
                 {
                     rgbValues = new byte[bytes];

                 }
                 else
                 {
                     byte[] ba = rgbValues.Skip(lnBytes).ToArray();
                     rgbValues = new byte[bytes];
                     ba.CopyTo(rgbValues, 0);
                 }

                 for (int y = bmp.Height-1; y < bmp.Height; y++)
                 {
                     byte[] ln = new byte[bmp.Width * 4];
                     for (int x = 0; x < bmp.Width; x++)
                     {
                         byte l = byte((x + y + bmOfs) % 256);
                         ln[x * 4 + 0] = l;
                         ln[x * 4 + 1] = l;
                         ln[x * 4 + 2] = l;
                         ln[x * 4 + 3] = 255;
                     }
                     ln.CopyTo(rgbValues, lnBytes * (bmp.Height - 1));
                 }

System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, 
bmp.Height * lnBytes);

                 bmp.UnlockBits(bmd);

                 bmOfs++;
                 if (bmOfs > bmp.Height) bmOfs = 0;

                 pictureBox1.Image = bmp.Clone() as Image;
             }
             pictureBox1.Image = null;
         }


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



Další informace o konferenci Hw-list