Commit 2947ab57 by Tapio Haapala

Image crop fix

1 parent aa3c033b
......@@ -1042,6 +1042,82 @@ namespace ImageFilters
grPhoto.Dispose();
return bmPhoto;
}
public static Bitmap Crop(Bitmap bmpPhoto, int Width, int Height, AnchorPosition Anchor)
{
//Scale crop
int sourceWidth = bmpPhoto.Width;
int sourceHeight = bmpPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentW;
switch (Anchor)
{
case AnchorPosition.Top:
destY = 0;
break;
case AnchorPosition.Bottom:
destY = (int)
(Height - (sourceHeight * nPercent));
break;
default:
destY = (int)
((Height - (sourceHeight * nPercent)) / 2);
break;
}
}
else
{
nPercent = nPercentH;
switch (Anchor)
{
case AnchorPosition.Left:
destX = 0;
break;
case AnchorPosition.Right:
destX = (int)
(Width - (sourceWidth * nPercent));
break;
default:
destX = (int)
((Width - (sourceWidth * nPercent)) / 2);
break;
}
}
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap bmPhoto = new Bitmap(Width,
Height, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(bmpPhoto.HorizontalResolution,
bmpPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode =
InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(bmpPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
public static Image Crop(Image imgPhoto, int Width, int Height, AnchorPosition Anchor, int x, int y)
{
// Size crop
......
......@@ -223,13 +223,13 @@ namespace MoyaSignup
if(c == null)
c = CameraService.AvailableCameras.First();
setFrameSource(new CameraFrameSource(c));
_frameSource.Camera.CaptureWidth = 1280;
_frameSource.Camera.CaptureHeight = 720;
//_frameSource.Camera.CaptureWidth = 1280;
//_frameSource.Camera.CaptureHeight = 720;
//_frameSource.Camera.CaptureWidth = 640;
//_frameSource.Camera.CaptureHeight = 480;
_frameSource.Camera.CaptureWidth = 640;
_frameSource.Camera.CaptureHeight = 480;
_frameSource.Camera.Fps = 50;
_frameSource.Camera.Fps = 15;
_frameSource.NewFrame += OnImageCaptured;
pbIncoming.Paint += new PaintEventHandler(drawLatestImage);
......@@ -271,7 +271,7 @@ namespace MoyaSignup
int y = (frame.Image.Height - RetangleHeight)/2;
y = frame.Image.Height - y;
latestFrame = BitmapFilter.Crop(frame.Image, RetangleWidth, RetangleHeight, ImageFilters.BitmapFilter.AnchorPosition.Free, 0, 0);
latestFrame = BitmapFilter.Crop(frame.Image, RetangleWidth, RetangleHeight, ImageFilters.BitmapFilter.AnchorPosition.Free);
//_latestFrame.RotateFlip(RotateFlipType.RotateNoneFlipY);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!