libimobiledevice-win32 / imobiledevice-net

.NET (C#, VB.NET,...) bindings for libimobiledevice
GNU Lesser General Public License v2.1
301 stars 77 forks source link

How do I save a screenshot? #202

Closed Dani-error closed 11 months ago

Dani-error commented 2 years ago

I want to know how to save a screenshot that I taked... This is my code:

                ReadOnlyCollection<string> udids;
                int count = 0;

                var idevice = LibiMobileDevice.Instance.iDevice;

                idevice.idevice_get_device_list(out udids, ref count);

                if (count == 0)
                {
                                return;
                }

                string udid = udids[0];

                idevice.idevice_new(out deviceHandle, udid).ThrowOnError();

                var springboard = LibiMobileDevice.Instance.SpringBoardServices;

                SpringBoardServicesClientHandle springboardServices;

                springboard.sbservices_client_start_service(deviceHandle, out springboardServices, "Orbit");

                IntPtr imgData = IntPtr.Zero;
                ulong imgSize = 0;

                springboard.sbservices_get_home_screen_wallpaper_pngdata(springboardServices, ref imgData, ref imgSize);

                Console.WriteLine(imgData + " " + imgSize);

                deviceHandle.Dispose();
                springboardServices.Dispose();

But I don't know how to save the IntPtr...

for40255 commented 11 months ago

byte[] managedArray = new byte[imgsize]; Marshal.Copy(imgdata, managedArray, 0, (int)imgsize); File.WriteAllBytes(Path.Combine(path, filename), managedArray);