Adjusting image size in XML request ?

,

I’m working on an image fetch from a live video feed and found a good base example in the SDK package.

I would like to request an image in a different size the than the standard HD resolution and I have an idea that the XML, which is send to the server could be modified like this.

But without the desired resize of the image received:

“<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>0” +

                "<methodname>connect</methodname><username></username><password></password>" +

                "<cameraid>{0}</cameraid><width>600</width><height>400</height><alwaysstdjpeg>yes</alwaysstdjpeg>" +

                "<connectparam>id={1}&amp;connectiontoken={2}" +

                "</connectparam></methodcall>\\r\\n\\r\\n

Is this impossible to do from the XML request ?

If so, how do I do this in C# ?

Starting with your last question. When doing C# I recommend that you use JPEGLiveSource (and/or JPEGVideoSource) and in that case there is no XML to format first.

You can set width and height in the Init() or set the properties after initialization.

JPEGLiveSource and JPEGVideoSource are used in the CameraStreamResolution sample.

When looking at the JPEGLiveSource example and especially the GetResLive method:

static void GetResLive(Guid streamid)

   {

       var jpegLive = new JPEGLiveSource(\_camera);

       if(streamid != Guid.Empty) jpegLive.StreamId = streamid;

       \_timeoutEvent = new Timer(TimeOutCallBack, null, 10000, 10000);

       jpegLive.LiveModeStart = true;

       jpegLive.Height = 0;

       jpegLive.Width = 0;

       jpegLive.Init();

       jpegLive.LiveContentEvent += jpegLiveContentEventHandler;

       \_resetEvent.WaitOne();

       \_timeoutEvent.Dispose();

       jpegLive.LiveContentEvent -= jpegLiveContentEventHandler;

   }

I’m wondering what type data is jpegLive and can it be saved as Bytes with WriteAllBytes as in my start-off example ?

I believe this thread hold the answer.. https://developer.milestonesys.com/s/article/How-to-save-a-JPEG-image-file-based-on-JpegData

Yes, it looks pretty much like the saving procedure from my start-off example - starting from the Array.Copy, I guess the leading commands will prepare it for saving as Bytes.

I’ll give it a try and all you folks now…

Well, for starters I need an explicit cast from JPEGLiveSource to JPEGData - does a workaround, some method exist ?

I realize I left out a piece and in the documentation I do not find the answer..

See the jpegLiveContentEventHandler in the sample I mention and add..

int len = args.LiveContent.Content.GetLength(0); 
Byte[] jpeg = new Byte[len];
Array.Copy(args.LiveContent.Content, 0, jpeg, 0, len);
string fname = @"C:\TEST\test.jpg"; ;
System.IO.File.WriteAllBytes(fname, jpeg);
Console.WriteLine("Written to disk. " + fname);

I guess LiveContent.Content is equivalent to JPEGData.Bytes and this is the information I should have included in my first reply..

Well, I’ve got the GeResLive - but it won’t fire up jpegLiveContentEventHandler when executing - the two methods:

static void GetResLive(Item camera, string dir)

   {

       var jpegLive = new JPEGLiveSource(camera);

       jpegLive.StreamId = Guid.NewGuid();

       timeoutEvent = new Timer(TimeOutCallBack, null, 10000, 10000);

       jpegLive.LiveModeStart = true;

       jpegLive.Height = 0;

       jpegLive.Width = 0;

       jpegLive.Init();

       jpegLive.LiveContentEvent += jpegLiveContentEventHandler;

       resetEvent.WaitOne();

       timeoutEvent.Dispose();

       jpegLive.LiveContentEvent -= jpegLiveContentEventHandler;

   }

   static void **jpegLiveContentEventHandler**(object sender, EventArgs e)

   {

       var args = e as LiveContentEventArgs;

       if (args != null)

       {

           if (args.LiveContent != null)

           {

               int len = args.LiveContent.Content.GetLength(0);

               Byte\[\] jpeg = new Byte\[len\];

               Array.Copy(args.LiveContent.Content, 0, jpeg, 0, len);

               string fname = @"[d:\\\\\\\\PathToImages](file:d:////PathToImages)";

               System.IO.File.WriteAllBytes(fname, jpeg);

               Console.WriteLine("Written to disk. " + fname);

           }

       }

       resetEvent.Set();

   }

I believe I got the declarations nessesary:

   private static Timer timeoutEvent;

   static AutoResetEvent resetEvent;

So why won’t it launch the Eventhandler ?

Did the event handler work before you modified the sample? Does the unmodified sample work for you?

Now the simplest explanation would be tat the event handler does not get triggered if the camera is not streaming images, please verify using another sample or Smart Client that you have live images.

Another idea; verify that you have copied the dependent files. In the sample you could have a post build event like this –

cd “$(ProjectDir)..\..\bin”

call CopyMedia.bat “$(TargetDir)”

--

Basically use the CopyMedia.bat in the SDK bin folder to copy the needed files.

Well, I’ll admit that I returned to original solution and resized the obtained image by:

Image fullsizeImage = (Bitmap)((new ImageConverter()).ConvertFrom(jpeg)); //jpeg is a byte array

Image newImage = fullsizeImage.GetThumbnailImage(600, 400, null, IntPtr.Zero);

And then saved the resized image.

I did not want to spend more time on the second version - sorry. :pensive_face: