- Extended CJMS11 camera handling with new functionalities, including image grabbing, resolution configuration, and improved ROI support. - Added new `ToString` method implementations for enhanced debugging and logging in key classes like `JmsMessage`, `JmsPacket`, and `RoiCfg`. - Introduced additional commands (`start_stream_images`, `stop_stream_images`) in `CommandM` and its enum. - Implemented new resolution handling in `RoiCfg` with support for configurable image frames. - Refactored resolution-related UI elements in `RoiCfgCtrl` to add a dropdown for selecting resolution. - Made minor UX improvements by replacing inconsistent string formats with verbatim strings in console messages. - Updated project dependencies with new resolution-related utilities (`Frame` and `ResolutionFrames`). - Resolved camera-specific symbolic issues by transitioning to `CJMS11.Camera` over prior naming inconsistencies.
71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using Common;
|
|
|
|
namespace TBF.Rig.Network.Camera.common
|
|
{
|
|
public class ImageUtils
|
|
{
|
|
|
|
public static void Rotate(Image image, ImageRotation direction)
|
|
{
|
|
if(!(direction == ImageRotation.Deg90 || direction == ImageRotation.Deg180 || direction == ImageRotation.Deg270))
|
|
return;
|
|
if (image == null)
|
|
throw new ArgumentNullException(nameof(image));
|
|
|
|
RotateFlipType flipType =
|
|
direction == ImageRotation.Deg90 ? RotateFlipType.Rotate90FlipNone :
|
|
direction == ImageRotation.Deg180 ? RotateFlipType.Rotate180FlipNone :
|
|
direction == ImageRotation.Deg270 ? RotateFlipType.Rotate270FlipNone :
|
|
RotateFlipType.RotateNoneFlipNone;
|
|
|
|
|
|
image.RotateFlip(flipType);
|
|
}
|
|
public static Image RotateCustom(Image image, ImageRotation direction)
|
|
{
|
|
if (image == null)
|
|
throw new ArgumentNullException(nameof(image));
|
|
|
|
int newWidth = image.Width;
|
|
int newHeight = image.Height;
|
|
|
|
RotateFlipType flipType;
|
|
|
|
switch (direction)
|
|
{
|
|
case ImageRotation.Deg90:
|
|
flipType = RotateFlipType.Rotate90FlipNone;
|
|
newWidth = image.Height;
|
|
newHeight = image.Width;
|
|
break;
|
|
case ImageRotation.Deg180:
|
|
flipType = RotateFlipType.Rotate180FlipNone;
|
|
break;
|
|
case ImageRotation.Deg270:
|
|
flipType = RotateFlipType.Rotate270FlipNone;
|
|
newWidth = image.Height;
|
|
newHeight = image.Width;
|
|
break;
|
|
default:
|
|
throw new ArgumentException("Unsupported rotation direction");
|
|
}
|
|
|
|
Bitmap rotated = new Bitmap(newWidth, newHeight);
|
|
using (Graphics g = Graphics.FromImage(rotated))
|
|
{
|
|
g.TranslateTransform(newWidth / 2f, newHeight / 2f);
|
|
g.RotateTransform(
|
|
direction == ImageRotation.Deg90 ? 90 :
|
|
direction == ImageRotation.Deg180 ? 180 :
|
|
direction == ImageRotation.Deg270 ? 270 :
|
|
0);
|
|
g.TranslateTransform(-image.Width / 2f, -image.Height / 2f);
|
|
g.DrawImage(image, new PointF(0, 0));
|
|
}
|
|
|
|
return rotated;
|
|
}
|
|
}
|
|
} |