# Access the image buffer to send address outside

**URL:** <https://forum.commonvisionblox.com/t/access-the-image-buffer-to-send-address-outside/999>\
**Category:** .Net API\
**Created:** [January 2, 2020, 1:58pm UTC](https://forum.commonvisionblox.com/t/access-the-image-buffer-to-send-address-outside/999 "2020-01-02T13:58:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amsted34](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@amsted34](https://forum.commonvisionblox.com/u/amsted34)\
**Post date:** [January 2, 2020, 1:58pm UTC](https://forum.commonvisionblox.com/t/access-the-image-buffer-to-send-address-outside/999/1 "2020-01-02T13:58:04Z")

</div>

Hi,

I would like to ask a bit of your help to use the image to be sent to an external Api for Processing. this external API ( Barcode reader ) takes a pointer address, width and height.

I have Managed to get it working Ok with the following Code but I have to make a copy to an array to retrieve an address to the image buffer - what I would like is read direct from the image ( I am using [cvb.net](http://cvb.net))

thanks for the help.

```auto
     public int DecodeByte(Device device, int ROITop, int ROILeft, int ROIWidth, int ROIHeight)
     {
          int retCode;
          int offset = 0;
          var img = device.DeviceImage.Planes[0].Map().MapTo8Bit();

          var width = img.Width;
          var height = img.Height;
          var myNewImage = img.Planes[0].GetLinearAccess();

          var pBase = myNewImage.BasePtr;
          var XInc = myNewImage.XInc;
          var YInc = myNewImage.YInc;
          byte[] srcVal2 = new byte[width * height];

          for (int y = 0; y < height; y++)
          {
              byte* pSrcLine = (byte*)pBase + y * (int)YInc;

              for (int x = 0; x < width; x++)
              {
                  var srcVal = *(pSrcLine + x * (int)XInc);
                  srcVal2[offset++] = srcVal;
              }
          }
          
          fixed (byte* pix = &srcVal2[0])
          {
              // Set image properties
              CRD_Set(handle, P_IMAGE_ADDRESS, (void*)pix); // address of Image here
              CRD_Set(handle, P_IMAGE_WIDTH, (void*)width);
              CRD_Set(handle, P_IMAGE_HEIGHT, (void*)height);
              CRD_Set(handle, P_IMAGE_BUF_WIDTH, (void*)width);
              // Set Region of Interest for decoding
              CRD_Set(handle, P_BC_ROI_TOP, (void*)ROITop);
              CRD_Set(handle, P_BC_ROI_LEFT, (void*)ROILeft);
              CRD_Set(handle, P_BC_ROI_WIDTH, (void*)ROIWidth);
              CRD_Set(handle, P_BC_ROI_HEIGHT, (void*)ROIHeight);
              CRD_Set(handle, P_ENABLE_QR_2005, (void*)1);
              retCode = CRD_Decode(handle);
          }
          return retCode;
       }

```

---

<div class="post-metadata">

**Author:** ![amsted34](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@amsted34](https://forum.commonvisionblox.com/u/amsted34)\
**Post date:** [January 3, 2020, 4:16pm UTC](https://forum.commonvisionblox.com/t/access-the-image-buffer-to-send-address-outside/999/2 "2020-01-03T16:16:40Z")

</div>

Nevermind, found my bug-  
I believe Pbase is already in a fixed statement hence putting inside another fixed statement didn’t make the compiler happy.

Moving everything outside the fixed statement did the trick to pass the Image Address to a third party Api.

Cheers

---

<div class="post-metadata">

**Author:** ![illusive](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/illusive/32/61_2.png) [@illusive](https://forum.commonvisionblox.com/u/illusive)\
**Post date:** [January 7, 2020, 7:44am UTC](https://forum.commonvisionblox.com/t/access-the-image-buffer-to-send-address-outside/999/3 "2020-01-07T07:44:55Z")

</div>

Hi @amsted34!

Sorry for the delayed reply. Your finding is correct: The base pointer returned for linear access is generally fixed (the `Stemmer.Cvb.Image` object is a proper CLR-object, but the memory in which the image is stored resides on the unmanaged heap, therefore the pixel data is not subject to being moved around during heap reorganization of the CLR, so unlike with e. g. the `System.Drawing.Bitmap` you don’t need to worry about pinning it before passing it to another unmanaged library.

---

<div class="post-metadata">

**Author:** ![amsted34](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@amsted34](https://forum.commonvisionblox.com/u/amsted34)\
**Post date:** [January 7, 2020, 10:45am UTC](https://forum.commonvisionblox.com/t/access-the-image-buffer-to-send-address-outside/999/4 "2020-01-07T10:45:52Z")

</div>

Thanks @illusive for adding your input on this especially the extra explanation that goes with it 😉

Cheers,  
Amine
