צור צילומי מסך מושלמים של אתרים או המר HTML ישירות לתמונות על ידי שימוש בתכונות הבאות של ממשק ה- API של GrabzIt. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל URLToImage, HTMLToImage or FileToImage שיטות Save or SaveTo יש לקרוא לשיטה לצילום המסך.
רק פרמטר אחד נדרש כדי לצלם צילום מסך של דף אינטרנט או להמיר HTML into תמונה קובץ. כמוצג בדוגמה הבאה.
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
ה- API של Java של GrabzIt יכול לצלם תמונות מסך בכמה פורמטים, כולל JPG, PNG, WEBP, BMP (ביט 8, 16, 24 או 32) ו- TIFF. פורמט ברירת המחדל עבור צילומי מסך של תמונות הוא JPG. עם זאת איכות התמונה של JPEG עשויה להיות לא מספיק טובה עבור אפליקציות מסוימות בנסיבות אלה, פורמט 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.setFormat(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.setFormat(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.setFormat(ImageFormat.PNG); grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.png");
גודל הדפדפן מתייחס לגודל חלון הדפדפן שישמש בעת צילום הצילום המסך ברוב המקרים, אין צורך להגדיר זאת מכיוון שגודל ברירת המחדל של הדפדפן יספיק כמעט לכל המשימות. כדי לקבוע את גודל הדפדפן פשוט העבירו ערך ל- setBrowserWidth
ו setBrowserHeight
שיטות של ImageOptions מעמד.
קל לשנות את גודל התמונה, לעשות את זה בלי לעוות את התמונה זה קצת יותר קשה. כדי להפוך את כל התהליך לפשוט יותר אנו ממליצים להשתמש בזה מחשבון מימד תמונה פשוט.
אם ברצונך להגדיל את רוחב וגובה התמונה לגודל גדול יותר מרוחב וגובה הדפדפן, אשר כברירת מחדל הוא 1366 על ידי 728 פיקסלים, יש להגדיל את רוחב הגובה של הדפדפן כך שיתאים.
אתה יכול להעביר מזהה מותאם אישית אל ה- תמונה שיטות כמוצג להלן, ערך זה יוחזר למטפל GrabzIt Java שלך. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך צילום מסך לרשומת מסד נתונים מסוימת.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.setCustomId("123456"); grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save method grabzIt.Save("http://www.example.com/handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.setCustomId("123456"); grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save method grabzIt.Save("http://www.example.com/handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.setCustomId("123456"); grabzIt.FileToImage("example.html", options); //Then call the Save method grabzIt.Save("http://www.example.com/handler");
GrabzIt מאפשר לך לצלם צילום מסך מלא של דף אינטרנט שלם כדי לעשות זאת אתה צריך להעביר -1 ל setBrowserHeight
שיטה. כדי להבטיח שהתמונה תואמת את גודל הדפדפן, העבירו כ- 1 ל- setHeight
ו setWidth
שיטות.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.setBrowserHeight(-1); options.setWidth(-1); options.setHeight(-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.setBrowserHeight(-1); options.setWidth(-1); options.setHeight(-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.setBrowserHeight(-1); options.setWidth(-1); options.setHeight(-1); grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
אתה יכול גם להחזיר תמונות ממוזערות שאינן קצוצות, אך היזהר מכיוון שיכול ליצור תמונות גדולות. לשם כך העבירו -1 ל- setHeight
ו / או setWidth
שיטות. כל מימד שמועבר ל- -1 לא ייחתך.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.setWidth(-1); options.setHeight(-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.setWidth(-1); options.setHeight(-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.setWidth(-1); options.setHeight(-1); grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
השימוש בערכים המיוחדים הללו פירושו שתוכלו ליצור צילום מסך המהווה גרסה בקנה מידה מלא של כל דף האינטרנט אם תרצו!
GrabzIt מאפשר לך לצלם צילום מסך של כל אלמנט HTML כל עוד יש לו תכונה מזהה או מחלקה, כגון div
or span
לתייג ולתפוס את כל תוכנו. לשם כך יש לציין את אלמנט ה- HTML שברצונך למסך למסך בורר CSS.
... <div id="features"> <img src="http://www.example.com/football.jpg"/><h3>Local Team Loses</h3> </div> ...
בדוגמה שלהלן נבדק ה- div עם המזהה "features" ומוצא כתמונת JPEG 250 x 250px.
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.setWidth(250); options.setHeight(250); options.setFormat(ImageFormat.JPG); options.setTargetElement("#features"); grabzIt.URLToImage("http://www.bbc.co.uk/news", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
הדוגמה הבאה שוב מצלמת את ה- div "תכונות" אך הפעם מוציא תמונה JPEG שהיא בדיוק באותו גודל של ה- div.
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.setWidth(-1); options.setHeight(-1); options.setBrowserHeight(-1); options.setFormat(ImageFormat.JPG); options.setTargetElement("#features"); grabzIt.URLToImage("http://www.bbc.co.uk/news", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");