mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Added image size reduction.
This commit is contained in:
parent
f4d47a6d34
commit
ed0cb0eca3
@ -15,14 +15,17 @@ namespace Remotely_ScreenCast.Capture
|
||||
{
|
||||
private static EncoderParameters EncoderParams { get; } = new EncoderParameters()
|
||||
{
|
||||
Param = new EncoderParameter[] { new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 0) }
|
||||
Param = new EncoderParameter[]
|
||||
{
|
||||
new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 25L),
|
||||
new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8L)
|
||||
}
|
||||
};
|
||||
|
||||
private static ImageCodecInfo CodecInfo { get; } = ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == ImageFormat.Png.Guid);
|
||||
|
||||
public static Bitmap GetImageDiff(Bitmap currentFrame, Bitmap previousFrame, bool captureFullscreen)
|
||||
{
|
||||
|
||||
if (currentFrame.Height != previousFrame.Height || currentFrame.Width != previousFrame.Width)
|
||||
{
|
||||
throw new Exception("Bitmaps are not of equal dimensions.");
|
||||
@ -95,10 +98,23 @@ namespace Remotely_ScreenCast.Capture
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
// Byte array that indicates top left coordinates of the image.
|
||||
bitmap.Save(ms, CodecInfo, EncoderParams);
|
||||
// Byte array that indicates top left coordinates of the image.
|
||||
return ms.ToArray();
|
||||
var bytes = ms.ToArray();
|
||||
if (bytes.Length > 200000)
|
||||
{
|
||||
var reducedBitmap = (Bitmap)bitmap.Clone();
|
||||
while (bytes.Length > 200000)
|
||||
{
|
||||
using (var ms2 = new MemoryStream())
|
||||
{
|
||||
reducedBitmap = new Bitmap(reducedBitmap, reducedBitmap.Width / 2, reducedBitmap.Height / 2);
|
||||
reducedBitmap.Save(ms2, CodecInfo, EncoderParams);
|
||||
bytes = ms2.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,14 +134,14 @@ namespace Remotely_ScreenCast
|
||||
|
||||
private static void StartWaitForViewerTimer()
|
||||
{
|
||||
var timer = new System.Timers.Timer(5000);
|
||||
var timer = new System.Timers.Timer(10000);
|
||||
timer.AutoReset = false;
|
||||
timer.Elapsed += (sender, arg) =>
|
||||
{
|
||||
// Shut down if no viewers have connected within 5 seconds.
|
||||
// Shut down if no viewers have connected within 10 seconds.
|
||||
if (Viewers.Count == 0)
|
||||
{
|
||||
Logger.Write("No viewers connected after 5 seconds. Shutting down.");
|
||||
Logger.Write("No viewers connected after 10 seconds. Shutting down.");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Remotely_Server.Data
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
this.Database.Migrate();
|
||||
//this.Database.Migrate();
|
||||
}
|
||||
public DbSet<CommandContext> CommandContexts { get; set; }
|
||||
|
||||
|
||||
@ -263,7 +263,7 @@ namespace Remotely_Server.Data
|
||||
RemotelyContext.Devices.ForEachAsync(x =>
|
||||
{
|
||||
x.IsOnline = false;
|
||||
});
|
||||
}).Wait();
|
||||
RemotelyContext.SaveChanges();
|
||||
}
|
||||
|
||||
@ -441,21 +441,21 @@ namespace Remotely_Server.Data
|
||||
.ForEachAsync(x =>
|
||||
{
|
||||
RemotelyContext.Remove(x);
|
||||
});
|
||||
}).Wait();
|
||||
|
||||
RemotelyContext.CommandContexts
|
||||
.Where(x => DateTime.Now - x.TimeStamp > TimeSpan.FromDays(AppConfig.DataRetentionInDays))
|
||||
.ForEachAsync(x =>
|
||||
{
|
||||
RemotelyContext.Remove(x);
|
||||
});
|
||||
}).Wait();
|
||||
|
||||
RemotelyContext.Devices
|
||||
.Where(x => DateTime.Now - x.LastOnline > TimeSpan.FromDays(AppConfig.DataRetentionInDays))
|
||||
.ForEachAsync(x =>
|
||||
{
|
||||
RemotelyContext.Remove(x);
|
||||
});
|
||||
}).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ export class RCBrowserSockets {
|
||||
var url = window.URL.createObjectURL(new Blob([buffer]));
|
||||
var img = document.createElement("img");
|
||||
img.onload = () => {
|
||||
UI.Screen2DContext.drawImage(img, 0, 0);
|
||||
UI.Screen2DContext.drawImage(img, 0, 0, UI.ScreenViewer.width, UI.ScreenViewer.height);
|
||||
window.URL.revokeObjectURL(url);
|
||||
};
|
||||
img.src = url;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -122,7 +122,7 @@ export class RCBrowserSockets {
|
||||
var url = window.URL.createObjectURL(new Blob([buffer]));
|
||||
var img = document.createElement("img");
|
||||
img.onload = () => {
|
||||
UI.Screen2DContext.drawImage(img, 0, 0);
|
||||
UI.Screen2DContext.drawImage(img, 0, 0, UI.ScreenViewer.width, UI.ScreenViewer.height);
|
||||
window.URL.revokeObjectURL(url);
|
||||
};
|
||||
img.src = url;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user