|
@@ -91,40 +91,44 @@ namespace WingAIDiagnosisService.Service
|
|
|
using (var bitmap = CreateBitmap(frameImage))
|
|
|
{
|
|
|
Logger.WriteLineInfo($"AIDiagnosisService VidImageZoomAsync RawImage, remedicalCode:{remedicalCode}");
|
|
|
- var rawImage = new RawImage(bitmap.Bytes, bitmap.Width, bitmap.Height, MapTo(bitmap.ColorType));
|
|
|
- // File.WriteAllBytes(Path.Combine(currentFolder, "123123.png"), frameImage.ImageData);
|
|
|
- Logger.WriteLineInfo($"AIDiagnosisService VidImageZoomAsync ImageRegion, remedicalCode:{remedicalCode}");
|
|
|
- var imageRegion = new List<Rect>();
|
|
|
- if (request.ImageRegion?.Any() ?? false)
|
|
|
+ using (var rawImage = new RawImage(bitmap.Bytes, bitmap.Width, bitmap.Height, MapTo(bitmap.ColorType)))
|
|
|
{
|
|
|
- foreach (var item in request.ImageRegion)
|
|
|
+ // File.WriteAllBytes(Path.Combine(currentFolder, "123123.png"), frameImage.ImageData);
|
|
|
+ Logger.WriteLineInfo($"AIDiagnosisService VidImageZoomAsync ImageRegion, remedicalCode:{remedicalCode}");
|
|
|
+ var imageRegion = new List<Rect>();
|
|
|
+ if (request.ImageRegion?.Any() ?? false)
|
|
|
{
|
|
|
- imageRegion.Add(new Rect((int)item.Left, (int)item.Top, (int)item.Width, (int)item.Height));
|
|
|
+ foreach (var item in request.ImageRegion)
|
|
|
+ {
|
|
|
+ imageRegion.Add(new Rect((int)item.Left, (int)item.Top, (int)item.Width, (int)item.Height));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- var sampleBoxReq = request.SampleBox ?? new ImageRect();
|
|
|
- var sampleBox = new AI.Common.Rectangle(new Rect((int)sampleBoxReq.Left, (int)sampleBoxReq.Top, (int)sampleBoxReq.Width, (int)sampleBoxReq.Height));
|
|
|
- var resizeType = (EnumResizeMethodType)request.ResizeType;
|
|
|
- Logger.WriteLineInfo($"AIDiagnosisService VidImageZoomAsync PushOneImage, remedicalCode:{remedicalCode}");
|
|
|
- Logger.WriteLineInfo($"imageRegion:{Newtonsoft.Json.JsonConvert.SerializeObject(imageRegion)}");
|
|
|
- Logger.WriteLineInfo($"sampleBox:{Newtonsoft.Json.JsonConvert.SerializeObject(sampleBox)}");
|
|
|
- var imageResizeBytes = ImageResize.PushOneImage(rawImage, imageRegion.ToArray(), sampleBox, resizeType);
|
|
|
- if (imageResizeBytes != null)
|
|
|
- {
|
|
|
- SKImageInfo info = new SKImageInfo((int)bitmap.Width, (int)bitmap.Height, SKColorType.Bgra8888, SKAlphaType.Unpremul);
|
|
|
-
|
|
|
- // Create an SKBitmap with the given SKImageInfo
|
|
|
- SKBitmap skBitmap = new SKBitmap(info);
|
|
|
- // Copy the pixel data from the imagePixels array to the SKBitmap
|
|
|
- using (SKImage skImage = SKImage.FromPixelCopy(info, imageResizeBytes))
|
|
|
+ var sampleBoxReq = request.SampleBox ?? new ImageRect();
|
|
|
+ var sampleBox = new AI.Common.Rectangle(new Rect((int)sampleBoxReq.Left, (int)sampleBoxReq.Top, (int)sampleBoxReq.Width, (int)sampleBoxReq.Height));
|
|
|
+ var resizeType = (EnumResizeMethodType)request.ResizeType;
|
|
|
+ Logger.WriteLineInfo($"AIDiagnosisService VidImageZoomAsync PushOneImage, remedicalCode:{remedicalCode}");
|
|
|
+ Logger.WriteLineInfo($"imageRegion:{Newtonsoft.Json.JsonConvert.SerializeObject(imageRegion)}");
|
|
|
+ Logger.WriteLineInfo($"sampleBox:{Newtonsoft.Json.JsonConvert.SerializeObject(sampleBox)}");
|
|
|
+ var imageResizeBytes = ImageResize.PushOneImage(rawImage, imageRegion.ToArray(), sampleBox, resizeType);
|
|
|
+ if (imageResizeBytes != null)
|
|
|
{
|
|
|
- skImage?.ReadPixels(skBitmap.Info, skBitmap.GetPixels(), skBitmap.RowBytes, 0, 0);
|
|
|
- }
|
|
|
- using (var image = SKImage.FromBitmap(skBitmap))
|
|
|
- using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
|
|
|
- {
|
|
|
- byte[] imageBytes = data.ToArray();
|
|
|
- resultData.Base64String = Convert.ToBase64String(imageBytes);
|
|
|
+ SKImageInfo info = new SKImageInfo((int)bitmap.Width, (int)bitmap.Height, SKColorType.Bgra8888, SKAlphaType.Unpremul);
|
|
|
+
|
|
|
+ // Create an SKBitmap with the given SKImageInfo
|
|
|
+ using (SKBitmap skBitmap = new SKBitmap(info))
|
|
|
+ {
|
|
|
+ // Copy the pixel data from the imagePixels array to the SKBitmap
|
|
|
+ using (SKImage skImage = SKImage.FromPixelCopy(info, imageResizeBytes))
|
|
|
+ {
|
|
|
+ skImage?.ReadPixels(skBitmap.Info, skBitmap.GetPixels(), skBitmap.RowBytes, 0, 0);
|
|
|
+ }
|
|
|
+ using (var image = SKImage.FromBitmap(skBitmap))
|
|
|
+ using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
|
|
|
+ {
|
|
|
+ byte[] imageBytes = data.ToArray();
|
|
|
+ resultData.Base64String = Convert.ToBase64String(imageBytes);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
Logger.WriteLineInfo($"AIDiagnosisService VidImageZoomAsync end, remedicalCode:{remedicalCode}");
|