1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-14 12:15:48 +02:00

Fix screenshots with zoom & try to fix rendering issues

This commit is contained in:
chylex 2018-04-28 20:36:49 +02:00
parent 7558551859
commit 12525ac386
3 changed files with 30 additions and 14 deletions

View File

@ -15,11 +15,10 @@ sealed class FormNotificationScreenshotable : FormNotificationBase{
protected override bool CanDragWindow => false;
private readonly PluginManager plugins;
private readonly int width;
private int height;
public FormNotificationScreenshotable(Action callback, FormBrowser owner, PluginManager pluginManager, string html, int width) : base(owner, false){
this.plugins = pluginManager;
this.width = width;
browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback));
@ -36,11 +35,11 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin
}
using(IFrame frame = args.Browser.MainFrame){
ScriptLoader.ExecuteScript(frame, script.Replace("{width}", ClientSize.Width.ToString()), "screenshot");
ScriptLoader.ExecuteScript(frame, script.Replace("{width}", BrowserUtils.Scale(width, DpiScale).ToString()), "screenshot");
}
};
SetScreenshotHeight(1);
SetNotificationSize(width, 1024);
LoadTweet(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty));
}
@ -54,14 +53,20 @@ protected override string GetTweetHTML(TweetNotification tweet){
return html;
}
private void SetScreenshotHeight(int height){
SetNotificationSize(width, height);
private void SetScreenshotHeight(int browserHeight){
this.height = BrowserUtils.Scale(browserHeight, SizeScale);
}
public bool TakeScreenshot(){
if (ClientSize.Height == 0){
FormMessage.Error("Screenshot Failed", "Could not detect screenshot size.", FormMessage.OK);
return false;
public bool TakeScreenshot(bool ignoreHeightError = false){
if (!ignoreHeightError){
if (height == 0){
FormMessage.Error("Screenshot Failed", "Could not detect screenshot size.", FormMessage.OK);
return false;
}
else if (height > ClientSize.Height){
FormMessage.Error("Screenshot Failed", $"Screenshot is too large: {height}px > {ClientSize.Height}px", FormMessage.OK);
return false;
}
}
IntPtr context = NativeMethods.GetDC(this.Handle);
@ -71,7 +76,7 @@ public bool TakeScreenshot(){
return false;
}
else{
using(Bitmap bmp = new Bitmap(ClientSize.Width, ClientSize.Height, PixelFormat.Format32bppRgb)){
using(Bitmap bmp = new Bitmap(ClientSize.Width, Math.Max(1, height), PixelFormat.Format32bppRgb)){
try{
NativeMethods.RenderSourceIntoBitmap(context, bmp);
}finally{

View File

@ -3,7 +3,7 @@
// #define NO_HIDE_SCREENSHOTS
// Uncomment to generate screenshots of individual frames for at most 1 second
#define GEN_SCREENSHOT_FRAMES
// #define GEN_SCREENSHOT_FRAMES
#endif
using System;
@ -128,7 +128,7 @@ private void StartDebugger(){
}
private void debugger_Tick(object sender, EventArgs e){
if (frameCounter < 63 && screenshot.TakeScreenshot()){
if (frameCounter < 63 && screenshot.TakeScreenshot(true)){
try{
Clipboard.GetImage()?.Save(Path.Combine(DebugScreenshotPath, "frame_"+(++frameCounter)+".png"), ImageFormat.Png);
}catch{

View File

@ -10,6 +10,17 @@
let avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0;
$TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9))).then(() => {
setTimeout($TD.triggerScreenshot, document.getElementsByTagName("iframe").length ? 267 : 67);
let framesLeft = 5; // basic render is done in 1 frame, large media take longer
let onNextFrame = function(){
if (--framesLeft < 0){
$TD.triggerScreenshot();
}
else{
requestAnimationFrame(onNextFrame);
}
};
onNextFrame();
});
})($TD_NotificationScreenshot);