ウェブサイトの完璧な画像スクリーンショットを作成するか、次の機能を使用してHTMLを直接画像に変換します GrabzItのASP.NET API。 ただし、開始する前に、 URLToImage, HTMLToImage or FileToImage メソッド Save or SaveTo スクリーンショットを撮るには、メソッドを呼び出す必要があります。
Webページのスクリーンショットを撮るために必要なパラメーターは1つだけです HTMLを変換 int画像を 次の例に示すように、
grabzIt.URLToImage("https://www.tesla.com"); //Then call the Save or SaveTo method
grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>"); //Then call the Save or SaveTo method
grabzIt.FileToImage("example.html"); //Then call the Save or SaveTo method
GrabzItのASP.NET APIは、JPG、PNG、WEBP、BMP(8ビット、16ビット、24ビットまたは32ビット)およびTIFFを含むいくつかの形式で画像のスクリーンショットを撮影できます。 画像のスクリーンショットのデフォルト形式はJPGです。 ただし、これらの状況の一部のアプリケーションではJPG画像の品質が十分ではない場合があります。画像のスクリーンショットには、品質とファイルサイズのバランスがとれるため、PNG形式が推奨されます。 以下の例は、PNG形式を使用して撮影された画像のスクリーンショットを示しています。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.Format = ImageFormat.png; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.png");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.Format = ImageFormat.png; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.png");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.Format = ImageFormat.png; grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.png");
ブラウザーサイズは、ほとんどすべてのタスクでデフォルトのブラウザーサイズで十分なので、ほとんどの場合、スクリーンショットをキャプチャするときに使用されるブラウザーウィンドウのサイズを指します。 ブラウザのサイズを設定するには、単に値を BrowserWidth
や BrowserHeight
のプロパティ ImageOptions とに提供されます。
画像のサイズを変更するのは簡単です。画像を歪めずに変更するのは少し難しいです。 プロセス全体を簡単にするために、これを使用することをお勧めします シンプルな画像寸法計算機.
画像の幅と高さをブラウザーの幅と高さ(デフォルトでは1366 x 728ピクセル)よりも大きくする場合、ブラウザーの幅と高さも一致するように増やす必要があります。
にカスタム識別子を渡すことができます 画像 次に示すメソッドを使用すると、この値はGrabzIt ASP.NETハンドラーに返されます。 たとえば、このカスタム識別子はデータベース識別子であり、スクリーンショットを特定のデータベースレコードに関連付けることができます。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.CustomId = "123456"; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.CustomId = "123456"; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.CustomId = "123456"; grabzIt.FileToImage("example.html", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
GrabzItを使用すると、Webページ全体のフルスクリーンのスクリーンショットを撮ることができます。これを行うには、-1を渡す必要があります BrowserHeight
のプロパティ ImageOptions クラス。 画像がブラウザのサイズと一致するようにするには、-1を OutputHeight
や OutputWidth
プロパティ。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.BrowserHeight = -1; options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.BrowserHeight = -1; options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.BrowserHeight = -1; options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
トリミングされていないサムネイルを返すこともできますが、大きな画像が作成される可能性があることに注意してください。 これを行うには、-1を渡します OutputHeight
および OutputWidth
プロパティ。 -1が渡されたディメンションは切り取られません。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
これらの特別な値を使用すると、必要に応じてWebページ全体のフルスケールバージョンのスクリーンショットを作成できます。
GrabzItでは、次のようなHTML要素のスクリーンショットを撮ることができます。 div
or span
タグを付け、そのすべてのコンテンツをキャプチャします。 これを行うには、スクリーンショットを作成するHTML要素を CSSセレクター.
... <div id="features"> <img src="http://www.example.com/hot.jpg"/><h3>Heatwave Starting</h3> </div> ...
以下の例では、idが「features」のdivを選択し、250 x 250px JPEGイメージとして出力します。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The 250 parameters indicates that image should be sized to 250 x 250 px ImageOptions options = new ImageOptions(); options.OutputWidth = 250; options.OutputHeight = 250; options.Format = ImageFormat.jpg; options.TargetElement = "#features"; grabzIt.URLToImage("http://www.bbc.co.uk/news", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
次の例では、「機能」divの別のスクリーンショットを撮りますが、今回はdivの正確なサイズであるJPEG画像を出力します。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The -1 indicates that image should not be cropped ImageOptions options = new ImageOptions(); options.OutputWidth = -1; options.OutputHeight = -1; options.BrowserHeight = -1; options.Format = ImageFormat.jpg; options.TargetElement = "#features"; grabzIt.URLToImage("http://www.bbc.co.uk/news", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");