# Writing Pixel Values to an Array

**URL:** <https://forum.commonvisionblox.com/t/writing-pixel-values-to-an-array/196>\
**Category:** C-style API\
**Tags:** vpat\
**Created:** [August 14, 2017, 1:21pm UTC](https://forum.commonvisionblox.com/t/writing-pixel-values-to-an-array/196 "2017-08-14T13:21:55Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [August 17, 2017, 3:08pm UTC](https://forum.commonvisionblox.com/t/writing-pixel-values-to-an-array/196/7 "2017-08-17T15:08:29Z")

</div>

@illusive: Homework done 🕶:

```auto
    using Cvb;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Threading.Tasks;

    namespace ArrayTestThatActuallyWritesToAList
    {
      class Program
      {
        static void Main(string[] args)
        {
          Image.IMG image;
          Image.CreateGenericImage(1, 4000, 200, false, out image);
          List<int> values = new List<int>();
          Stopwatch executionWatch = new Stopwatch();
          executionWatch.Start();
          CopyPixelsWithValue(image, values);
          executionWatch.Stop();
          Image.ReleaseObj(image);
          Console.WriteLine(executionWatch.ElapsedMilliseconds.ToString());
          Console.Read();
        }

        static unsafe void CopyPixelsWithValue(Image.IMG source, List<int> values)
        {
          int width = Image.ImageWidth(source);
          int height = Image.ImageHeight(source);
          IntPtr sourceBase;
          int sourceYInc;
          int sourceXInc;

          Cvb.Utilities.GetLinearAccess(source, 0, out sourceBase, out sourceXInc, out sourceYInc);

          Parallel.For(0, height, y =>
          {
            byte* pSrcLine = (byte*)sourceBase + y * sourceYInc;

            for (int x = 0; x < width; x++)
            {
              var srcVal = *(pSrcLine + x * sourceXInc);
              values.Add(srcVal);
            }
          });
        }
      }
    }

```

Didn’t feel very satisfying however 😶

@mave This should be pretty much copy-pasteable right now 😉

Cheers  
Chris

---

_[View the full topic](https://forum.commonvisionblox.com/t/writing-pixel-values-to-an-array/196)._
