public ImageData GetImage() { isConnected = true; lock (lockSave) { if (imageChanged && RenderTarget != null) { WriteableBitmap wb = new WriteableBitmap(RenderTarget); if (Config != null && app != null && currentSize != null && Config.HideControls) { var x = (int)(double.IsNaN(app.ChatMessageX) ? 0 : app.ChatMessageX); x = x < 0 ? 0 : x; var y = (int)(double.IsNaN(app.ChatBoxY) ? 0 : app.ChatBoxY); //var height = (int)System.Windows.Application.Current.MainWindow.Height - y; var height = (int)app.ChatBoxHeight > 0 ? (int)app.ChatBoxHeight : (int)System.Windows.Application.Current.MainWindow.Height - y; var width = (int)app.ChatMessageWidth > 0 ? (int)(app.ChatMessageWidth + x - app.ChatBoxX) : (int)app.ChatBoxWidth; currentSize.Width = width; currentSize.Height = height; wb = wb.Crop( (int)app.ChatBoxX, y, width, height); } else { currentSize.Width = wb.PixelWidth; currentSize.Height = wb.PixelHeight; } imageData.Size = currentSize; imageData.Pixels = null; imageData.Pixels = wb.ConvertToByteArray(); return(imageData); } else { return(null); } } }