-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenshot.cs
85 lines (78 loc) · 3.21 KB
/
Screenshot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// <copyright file="Screenshot.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace FB_API_Plugin.Webdriver
{
/// <summary>
/// Represents an image of the page currently loaded in the browser.
/// </summary>
[Serializable]
public class Screenshot
{
private string base64Encoded = string.Empty;
private byte[] byteArray;
/// <summary>
/// Initializes a new instance of the <see cref="Screenshot"/> class.
/// </summary>
/// <param name="base64EncodedScreenshot">The image of the page as a Base64-encoded string.</param>
public Screenshot(string base64EncodedScreenshot)
{
this.base64Encoded = base64EncodedScreenshot;
this.byteArray = Convert.FromBase64String(this.base64Encoded);
}
/// <summary>
/// Gets the value of the screenshot image as a Base64-encoded string.
/// </summary>
public string AsBase64EncodedString
{
get { return this.base64Encoded; }
}
/// <summary>
/// Gets the value of the screenshot image as an array of bytes.
/// </summary>
public byte[] AsByteArray
{
get { return this.byteArray; }
}
/// <summary>
/// Saves the screenshot to a file, overwriting the file if it already exists.
/// </summary>
/// <param name="fileName">The full path and file name to save the screenshot to.</param>
/// <param name="format">A <see cref="System.Drawing.Imaging.ImageFormat"/> object indicating the format
/// to save the image to.</param>
public void SaveAsFile(string fileName, ImageFormat format)
{
using (MemoryStream imageStream = new MemoryStream(this.byteArray))
{
Image screenshotImage = Image.FromStream(imageStream);
screenshotImage.Save(fileName, format);
}
}
/// <summary>
/// Returns a <see cref="System.String">String</see> that represents the current <see cref="System.Object">Object</see>.
/// </summary>
/// <returns>A <see cref="System.String">String</see> that represents the current <see cref="System.Object">Object</see>.</returns>
public override string ToString()
{
return this.base64Encoded;
}
}
}