|
|
@ -9,6 +9,7 @@ using System.Drawing; |
|
|
|
using System.Windows.Forms; |
|
|
|
using System.Windows.Interop; |
|
|
|
using System.Linq; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
namespace STDHelper |
|
|
|
{ |
|
|
@ -18,32 +19,50 @@ namespace STDHelper |
|
|
|
public partial class MainWindow : Window |
|
|
|
{ |
|
|
|
private DispatcherTimer t; |
|
|
|
private BitmapSource lastImage; |
|
|
|
public MainWindow() |
|
|
|
{ |
|
|
|
InitializeComponent(); |
|
|
|
System.Windows.Controls.ComboBox cb = FindName("cb_Screens") as System.Windows.Controls.ComboBox; |
|
|
|
Screen[] screens = Screen.AllScreens; |
|
|
|
foreach(Screen s in screens) |
|
|
|
{ |
|
|
|
cb.Items.Add(s.DeviceName); |
|
|
|
} |
|
|
|
cb.SelectedItem = cb.Items.GetItemAt(0); |
|
|
|
|
|
|
|
t = new DispatcherTimer(); |
|
|
|
// Hook up the Elapsed event for the timer.
|
|
|
|
t.Tick += new EventHandler(OnTimedEvent); |
|
|
|
t.Interval = new TimeSpan(0, 0, 1); |
|
|
|
} |
|
|
|
|
|
|
|
private void Btn_Load1_Click(object sender, RoutedEventArgs e) |
|
|
|
private WriteableBitmap getAreaFromBitmap(BitmapSource src, Int32Rect area) |
|
|
|
{ |
|
|
|
System.Windows.Controls.Image i = FindName("image1") as System.Windows.Controls.Image; |
|
|
|
LoadClipboardToImage(i); |
|
|
|
} |
|
|
|
// Calculate stride of source
|
|
|
|
int stride = src.PixelWidth * (src.Format.BitsPerPixel + 7) / 8; |
|
|
|
|
|
|
|
private void LoadClipboardToImage(System.Windows.Controls.Image img) |
|
|
|
{ |
|
|
|
BitmapSource bms = CopyScreen(); |
|
|
|
img.Opacity = 0.5; |
|
|
|
img.Source = bms; |
|
|
|
} |
|
|
|
// Create data array to hold source pixel data
|
|
|
|
byte[] data = new byte[stride * area.Height]; |
|
|
|
|
|
|
|
private void Btn_Load2_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
System.Windows.Controls.Image i = FindName("image2") as System.Windows.Controls.Image; |
|
|
|
LoadClipboardToImage(i); |
|
|
|
// Copy source image pixels to the data array
|
|
|
|
src.CopyPixels(area, data, stride, 0); |
|
|
|
|
|
|
|
// Create WriteableBitmap to copy the pixel data to.
|
|
|
|
WriteableBitmap target = new WriteableBitmap( |
|
|
|
area.Width, |
|
|
|
area.Height, |
|
|
|
src.DpiX, src.DpiY, |
|
|
|
src.Format, null); |
|
|
|
|
|
|
|
// Write the pixel data to the WriteableBitmap.
|
|
|
|
target.WritePixels( |
|
|
|
new Int32Rect(0, 0, area.Width, area.Height), |
|
|
|
data, stride, 0); |
|
|
|
|
|
|
|
// Set the WriteableBitmap as the source for the <Image> element
|
|
|
|
// in XAML so you can see the result of the copy
|
|
|
|
return target; |
|
|
|
} |
|
|
|
|
|
|
|
private void Btn_Switch_Click(object sender, RoutedEventArgs e) |
|
|
@ -86,16 +105,26 @@ namespace STDHelper |
|
|
|
|
|
|
|
private void Btn_LoadScreenshot_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
System.Windows.Controls.Image i = FindName("image1") as System.Windows.Controls.Image; |
|
|
|
LoadClipboardToImage(i); |
|
|
|
System.Windows.Controls.Image i1 = FindName("image1") as System.Windows.Controls.Image; |
|
|
|
System.Windows.Controls.Image i2 = FindName("image2") as System.Windows.Controls.Image; |
|
|
|
System.Windows.Controls.ComboBox cb = FindName("cb_Screens") as System.Windows.Controls.ComboBox; |
|
|
|
string scrStr = cb.SelectedItem as string; |
|
|
|
Screen screen = Screen.AllScreens.Where(elem => elem.DeviceName == scrStr).SingleOrDefault(); |
|
|
|
BitmapSource bms = CopyScreen(screen); |
|
|
|
WriteableBitmap crop1 = getAreaFromBitmap(bms, new Int32Rect(226, 123, 450, 450)); |
|
|
|
WriteableBitmap crop2 = getAreaFromBitmap(bms, new Int32Rect(685, 123, 450, 450)); |
|
|
|
i1.Source = crop1; |
|
|
|
i1.Opacity = 0.5; |
|
|
|
i2.Source = crop2; |
|
|
|
i2.Opacity = 0.5; |
|
|
|
} |
|
|
|
|
|
|
|
private static BitmapSource CopyScreen() |
|
|
|
private static BitmapSource CopyScreen(Screen screen) |
|
|
|
{ |
|
|
|
var left = Screen.AllScreens.Min(screen => screen.Bounds.X); |
|
|
|
var top = Screen.AllScreens.Min(screen => screen.Bounds.Y); |
|
|
|
var right = Screen.AllScreens.Max(screen => screen.Bounds.X + screen.Bounds.Width); |
|
|
|
var bottom = Screen.AllScreens.Max(screen => screen.Bounds.Y + screen.Bounds.Height); |
|
|
|
var left = screen.Bounds.X; |
|
|
|
var top = screen.Bounds.Y; |
|
|
|
var right = screen.Bounds.X + screen.Bounds.Width; |
|
|
|
var bottom = screen.Bounds.Y + screen.Bounds.Height; |
|
|
|
var width = right - left; |
|
|
|
var height = bottom - top; |
|
|
|
|
|
|
@ -112,6 +141,18 @@ namespace STDHelper |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void Btn_DbgSave_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
Debug.WriteLine("SAVE CLICK"); |
|
|
|
using (var fileStream = new FileStream("debug.png", FileMode.Create)) |
|
|
|
{ |
|
|
|
Debug.WriteLine("START SAVE"); |
|
|
|
BitmapEncoder encoder = new PngBitmapEncoder(); |
|
|
|
encoder.Frames.Add(BitmapFrame.Create(this.lastImage)); |
|
|
|
encoder.Save(fileStream); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class DraggableExtender : DependencyObject |
|
|
|