I am trying to send a picture through pipeline and spi in C#(Windows form), the pipes do connect but no image is showing,

So the thing i want to do is send an image as of right now a jpg to through pipeline that uses spi aswell, in the console it says that everything is connected but when i look at the windows form i see no image yet it says that everything is connected. I feel like a big problem is on the program.cs file (the last part), there is more code so pls inform me if anything feels unclear.

    public class PipeServer
        {
            public static async Task RunServerAsync(string imagePath)
            {
                try
                {
                    
                    // The server is created to send data, hence PipeDirection.
                    using (var server = new NamedPipeServerStream("datapipe", PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
                    {
                        //string imagepath2 = @"C:Usersu096849Desktopbildermc1.jpg";
                        //imagePath = imagepath2;
                        Console.WriteLine("Server waiting for connection...");
                        await server.WaitForConnectionAsync();
                        Console.WriteLine("Server connected to client.");
                        
                        if (File.Exists(imagePath))
                        {
                            using (Bitmap image = new Bitmap(imagePath))
                            {
                                Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
                                BitmapData bmpData = image.LockBits(rect,ImageLockMode.ReadOnly, image.PixelFormat);
        
                                IntPtr ptr = bmpData.Scan0;
        
                                int bytes = Math.Abs(bmpData.Stride) * image.Height;
                                byte[] rgbValues = new byte[bytes];
        
                                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
        
                                image.UnlockBits(bmpData);
        
                                int scaledWidth2 = (int)(image.Width * 1.0f);
                                int scaledHeight2 = (int)(image.Height * 1.0f);
        
                                if (scaledWidth2 <= 0) scaledWidth2 = 1;
                                if (scaledHeight2 <= 0) scaledHeight2 = 1;
        
                                Bitmap scaledImage = new Bitmap(scaledWidth2, scaledHeight2);
                                using (Graphics gfx = Graphics.FromImage(scaledImage))
                                {
                                    gfx.DrawImage(image, new Rectangle(0, 0, scaledWidth2, scaledHeight2));
                                }
        
                                await server.WriteAsync(rgbValues, 0, rgbValues.Length);
                                Console.WriteLine("Image sent successfully");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Error: Specified image path does not exist");
                        }
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine($"An error occurred in the client: {ex.Message}");
        
                }
        
        
        
            }
        }
         public class MockSpiDevice : ISpiDevice
         {
             private NamedPipeClientStream clientStream;
        
             public void Open()
             {
                 if (clientStream == null || !clientStream.IsConnected)
                 {
                     clientStream = new NamedPipeClientStream(".", "datapipe", PipeDirection.In);
                     clientStream.Connect();
                     Console.WriteLine("SPI connected");
                 }
                 else
                 {
                     Console.WriteLine("SPI already connected.");
                 }
             }
        
             public void Close()
             {
                 if (clientStream != null)
                 {
                     clientStream.Close();
                     clientStream = null;
                     Console.WriteLine("SPI disconnected");
                 }
             }
        
        
             public int Read(byte[] buffer, int offset, int count)
             {
                 if (clientStream != null && clientStream.CanRead)
                 {
                     return clientStream.Read(buffer, offset, count);
                 }
                 else
                 {
                     throw new InvalidOperationException("Attempt to read from an unconnected or closed stream.");
                 }
             }
        
        
             public int BytesToRead
             {
                 get
                 {
                     return (clientStream != null && clientStream.IsConnected) ? clientStream.InBufferSize : 0;
                 }
             }
        
         }
          public partial class DisplayForm : Form
          {
              bool bigDisplay = false;
              private float scaleFactor = 1.0f;
              private Bitmap originalImage;
              //private SerialPort spiPort = new SerialPort("");
              private ISpiDevice spiDevice;
              
              private PictureBox pictureBox;
              private Timer updateTimer;
        
        
              public PixelFormat Desktop { get; private set; }
        
              private enum Buttons
              {
                  A = 0b01000001,
                  B = 0b01000100,
                  Q = 0b01010001
              }
              public DisplayForm(ISpiDevice spiDevice)
              {
                  InitializeComponent();
                  this.Text = "Display Emulator : " + Application.ProductVersion;
        
                  //spiDevice = device;
                  pictureBox = new PictureBox()
                  {
                  Dock = DockStyle.Fill,
                  BorderStyle = BorderStyle.Fixed3D
                  };
                  this.Controls.Add(pictureBox);
        
                  updateTimer = new Timer() 
                  { 
                  Interval = 1000
                  };
                  updateTimer.Tick += UpdateTimer_Tick;
                  updateTimer.Start();
                      //this.window.Paint += new PaintEventHandler(Canvas_Paint);
        
                      /*
                      spiPort.BaudRate = 115200;
                      spiPort.DataBits = 8;
                      spiPort.Parity = Parity.None;
                      spiPort.StopBits = StopBits.One;
                      */
                  this.spiDevice = spiDevice;
                  SetupFromComponets();
                      //spiPort.Open();
        
        
                  zoomBar.Visible = false;
              }
              private async Task<Bitmap> ReadImageFromSPIAsync(ISpiDevice spiDevice)
              {
                  try
                  {
                      if (spiDevice.BytesToRead > 0)
                      {
                          byte[] buffer = new byte[spiDevice.BytesToRead];
                          int bytesRead = spiDevice.Read(buffer, 0, buffer.Length);
                          using (MemoryStream ms = new MemoryStream(buffer, 0, bytesRead))
                          {
                              return new Bitmap(ms);
                          }
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("Error reading from SPI: " + ex.Message);
                  }
                  return null;
              }
        
        
              private void SpiPort_DataRecevide(object sender, DataReceivedEventArgs e)
              {
                  // Handle incoming SPI data here
                  // For example, read the incoming data and convert it to an image
                  // Note: This will likely involve more complex handling including knowing the image format
        
                  // Be sure to invoke this action on the UI thread
        
                  this.Invoke((MethodInvoker)delegate
                  {
                      UpdateImageFromSPI();
                  });
              }
        
              private void UpdateImageFromSPI()
              {
                  byte[] imageData = ReadDataFromSPI();
                  originalImage = CovertToBitmap(imageData);
        
                  window.Invalidate();
              }
        
              private byte[] ReadDataFromSPI()
              {
                  byte[] buffer = new byte[spiDevice.BytesToRead];
                  spiDevice.Read(buffer, 0, buffer.Length);
                  return buffer;
              }
        
              private Bitmap CovertToBitmap(byte[] imageData)
              {
                  using (MemoryStream ms = new MemoryStream(imageData))
                  {
                      return new Bitmap(ms);
                  }
              }
        
              private async void UpdateTimer_Tick(object sender, EventArgs e)
              {
                  try
                  {
                      if (spiDevice != null && spiDevice.BytesToRead > 0)
                      {
                          var buffer = new byte[spiDevice.BytesToRead];
                          int bytesRead = spiDevice.Read(buffer, 0, buffer.Length);
                          if (bytesRead > 0)
                          {
                              using (MemoryStream ms = new MemoryStream(buffer))
                              {
                                  Bitmap newImage = new Bitmap(ms);
                                  pictureBox.Image?.Dispose();
                                  pictureBox.Image = newImage;
                                  pictureBox.Refresh();
                              }
                          }
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("Failed to update image from SPI: " + ex.Message);
                  }
              }
        }
 internal static class Program
 {
     /// <summary>
     /// The main entry point for the application.
     /// </summary>
 

     [STAThread]
     [DllImport("kernel32.dll", SetLastError = true)]
     [return: MarshalAs(UnmanagedType.Bool)]
     static extern bool AllocConsole();
     static void Main()
     {

         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);

         ISpiDevice spiDevice = new MockSpiDevice();
         string imagePath = (@"C:Usersu096849Desktopbildermc1.jpg");

         var serverTask = PipeServer.RunServerAsync(imagePath);
         spiDevice.Open();
         

         Application.Run(new DisplayForm(spiDevice));
     

     }
     static async Task PipeSetup(ISpiDevice spiDevice)
     {
         
         //MockSpiDevice mockSpiDevice = new MockSpiDevice();
         //mockSpiDevice.Open();

         //await Task.WhenAll(serverTask);
     }
 }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật