connect to csharp
This commit is contained in:
parent
0261b94820
commit
b88ff96b32
16 changed files with 336 additions and 63 deletions
35
StitchImg/ImageController.cs
Executable file
35
StitchImg/ImageController.cs
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace StitchImg;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/image")]
|
||||
public class ImageController : ControllerBase
|
||||
{
|
||||
[HttpPost("generate")]
|
||||
public async Task<IActionResult> Generate([FromBody] ImageSpecification specification)
|
||||
{
|
||||
var serverIp = "127.0.0.1";
|
||||
var port = 8080;
|
||||
|
||||
var tcpClient = new TcpClient();
|
||||
await tcpClient.ConnectAsync(serverIp, port);
|
||||
NetworkStream networkStream = tcpClient.GetStream();
|
||||
var writer = new BinaryWriter(networkStream);
|
||||
|
||||
string rect = specification.CanvasRect;
|
||||
byte[] rectBytes = Encoding.UTF8.GetBytes(rect);
|
||||
writer.Write((ushort)rectBytes.Length);
|
||||
writer.Write(rectBytes);
|
||||
writer.Write(specification.CropOffset[0]);
|
||||
writer.Write(specification.CropSize[0]);
|
||||
writer.Write(specification.CropOffset[1]);
|
||||
writer.Write(specification.CropSize[1]);
|
||||
writer.Write(specification.OutputScale);
|
||||
writer.Flush();
|
||||
|
||||
return File( networkStream, "image/png");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue