תמונת Monkey
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מחלקה של קוף שמחזיק תמונה של המכשיר או המסך של האמולטור. התמונה היא
מועתק ממאגר הנתונים הזמני של המסך במהלך צילום מסך. ה-methods של האובייקט הזה מאפשרות
להמיר את התמונה לפורמטים שונים של אחסון, לכתוב את התמונה לקובץ, להעתיק חלקים
את התמונה, ולהשוות את האובייקט הזה לאובייקטים אחרים של MonkeyImage
.
אין צורך ליצור מופעים חדשים של MonkeyImage
. במקום זאת, השתמשו
MonkeyDevice.takeSnapshot()
כדי ליצור מכונה חדשה מצילום מסך. לדוגמה:
newimage = MonkeyDevice.takeSnapshot()
סיכום
שיטות |
מחרוזת
|
ConversionToBytes
(פורמט מחרוזת)
ממירה את התמונה הנוכחית לפורמט מסוים ומחזירה אותה
string, שאליו אפשר לגשת בתור ערך איטרציה של בייטים בינאריים.
|
tuple
|
getRawPixel
(integer x,
שלם y)
מחזירה את הפיקסל היחיד במיקום התמונה (x,y),
tuple של integer, בפורמט (a,r,g,b).
|
מספר שלם
|
getRawPixelInt
(integer x,
שלם y)
הפונקציה מחזירה את הפיקסל היחיד במיקום התמונה (x,y), כפי
מספר שלם בגרסת 32 ביט.
|
MonkeyImage
|
getSubImage
(tuple מלבן)
יצירת אובייקט MonkeyImage חדש מתוך בחירה מלבנית של
התמונה הנוכחית.
|
בוליאני
|
sameAs
(MonkeyImage
other,
אחוז float)
משווה את האובייקט MonkeyImage הזה לאובייקט אחר, ומחזירה את התוצאה של
להשוואה. הארגומנט percent מציין את האחוז
מותר שתי התמונות יהיו "שוות".
|
ריק
|
writeToFile
(נתיב מחרוזת,
פורמט string)
כתיבת התמונה הנוכחית לקובץ שצוין על ידי filename , בפונקציית
פורמט שצוין על ידי format .
|
שיטות ציבוריות
ממירה את התמונה הנוכחית לפורמט מסוים ומחזירה אותה כ-string
שאחר כך אפשר לגשת אליו בתור ערך שאי אפשר לשנות לבייטים בינאריים.
ארגומנטים
פורמט |
פורמט הפלט הרצוי. יש תמיכה בכל הפורמטים הנפוצים של פלט רשת נקודות.
ערך ברירת המחדל הוא png. (Portable Network Graphics).
|
tuple
getRawPixel
(integer x,
integer y)
מחזירה את הפיקסל היחיד במיקום התמונה (x,y),
tuple של integer, בצורה (a,r,g,b).
ארגומנטים
x |
המיקום האופקי של הפיקסל, שמתחיל ב-0 בצד שמאל של המסך
את הכיוון שבו הוא היה כשצילום המסך צולם.
|
y |
המיקום האנכי של הפיקסל, שמתחיל ב-0 בחלק העליון של המסך
את הכיוון שבו הוא היה כשצילום המסך צולם.
|
החזרות
-
מספר של מספרים שלמים שמייצגים את הפיקסל בצורה (a,r,g,b)
a הוא הערך של ערוץ אלפא, ו-r, g ו-b הם הערכים אדומים, ירוק וכחול,
בהתאמה.
tuple
getRawPixelInt
(integer x,
integer y)
מחזירה את הפיקסל היחיד במיקום התמונה (x,y),
מספר שלם. תוכלו להשתמש בשיטה הזו כדי לחסוך בזיכרון.
ארגומנטים
x |
המיקום האופקי של הפיקסל, שמתחיל ב-0 בצד שמאל של המסך
את הכיוון שבו הוא היה כשצילום המסך צולם.
|
y |
המיקום האנכי של הפיקסל, שמתחיל ב-0 בחלק העליון של המסך
את הכיוון שבו הוא היה כשצילום המסך צולם.
|
החזרות
-
ערכי a,r,g ו-b של הפיקסל כערכי 8-ביט המשולבים לערכי 32-ביט
מספר שלם, כאשר r הוא 8 הביטים השמאליים ביותר, r הבא הכי מתאים וכו'.
MonkeyImage
getSubImage
(tuple מלבן)
יצירת אובייקט MonkeyImage
חדש מבחירה מלבנית של
התמונה הנוכחית.
ארגומנטים
rect |
קיבוע (x, y, w, h) שמציין את הבחירה. X ו-y מציינים את הפיקסלים שמבוססים על 0
של הפינה השמאלית העליונה של הבחירה. w מציין את הרוחב
ו-h מציין את הגובה שלו, גם ביחידות של פיקסלים.
כיוון התמונה זהה לכיוון המסך בזמן
צילום המסך בוצע.
|
החזרות
-
אובייקט
MonkeyImage
חדש שמכיל את הבחירה.
בוליאני
sameAs
(
MonkeyImage
otherImage,
אחוז float
)
משווה את האובייקט MonkeyImage
הזה לאובייקט אחר, ומחזירה את התוצאה של
להשוואה. הארגומנט percent
מציין את האחוז
מותר שתי התמונות יהיו "שוות".
ארגומנטים
אחר |
אובייקט MonkeyImage נוסף להשוואה לזה.
|
אחוז
|
מספר ממשי (float) בטווח 0.0 עד 1.0, כולל, שמציין
אחוז הפיקסלים שצריכים להיות זהים כדי שהשיטה תחזיר
true ברירת המחדל היא 1.0, שמציינת שכל הפיקסלים
חייב להיות תואם.
|
החזרות
-
ערך בוליאני
true
אם התמונות תואמות, או ערך בוליאני false
אחרת.
כתיבת התמונה הנוכחית לקובץ שצוין על ידי filename
, בפונקציית
פורמט שצוין על ידי format
.
ארגומנטים
נתיב |
שם הקובץ והסיומת המלאים של קובץ הפלט.
|
פורמט
|
פורמט הפלט שבו יש להשתמש עבור הקובץ. אם לא צוין פורמט,
שמנסה לנחש את הפורמט לפי הסיומת של שם הקובץ. אם לא
הוזן תוסף ולא צוין פורמט, אז פורמט ברירת המחדל של
"png" (Portable Network Graphics) נעשה שימוש.
|
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# MonkeyImage\n\nA monkeyrunner class to hold an image of the device or emulator's screen. The image is\ncopied from the screen buffer during a screenshot. This object's methods allow you to\nconvert the image into various storage formats, write the image to a file, copy parts of\nthe image, and compare this object to other `MonkeyImage` objects.\n\n\nYou do not need to create new instances of `MonkeyImage`. Instead, use\n[MonkeyDevice.takeSnapshot()](/tools/help/MonkeyDevice#takeSnapshot) to create a new instance from a screenshot. For example, use: \n\n```\nnewimage = MonkeyDevice.takeSnapshot()\n```\n\nSummary\n-------\n\n| Methods ||||||||||||\n|----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|---|---|---|---|---|---|---|---|---|\n| *string* | [convertToBytes](#convertToBytes) (*string* format) Converts the current image to a particular format and returns it as a *string* that you can then access as an *iterable* of binary bytes. |\n| *tuple* | [getRawPixel](#getRawPixel) (*integer* x, *integer* y) Returns the single pixel at the image location (x,y), as an a *tuple* of *integer*, in the form (a,r,g,b). |\n| *integer* | [getRawPixelInt](#getRawPixelInt) (*integer* x, *integer* y) Returns the single pixel at the image location (x,y), as a 32-bit *integer*. |\n| ` `[MonkeyImage](/tools/help/MonkeyImage)` ` | [getSubImage](#getSubImage) (*tuple* rect) Creates a new `MonkeyImage` object from a rectangular selection of the current image. |\n| *boolean* | [sameAs](#sameAs) ([MonkeyImage](/tools/help/MonkeyImage) other, *float* percent) Compares this `MonkeyImage` object to another and returns the result of the comparison. The `percent` argument specifies the percentage difference that is allowed for the two images to be \"equal\". |\n| *void* | [writeToFile](#writeToFile) (*string* path, *string* format) Writes the current image to the file specified by `filename`, in the format specified by `format`. |\n\nPublic methods\n--------------\n\n#### *string*\nconvertToBytes\n( *string* format)\n\n\nConverts the current image to a particular format and returns it as a *string*\nthat you can then access as an *iterable* of binary bytes. \n\n##### Arguments\n\n| format | The desired output format. All of the common raster output formats are supported. The default value is \"png\" (Portable Network Graphics). |\n|--------|-------------------------------------------------------------------------------------------------------------------------------------------|\n\n#### *tuple*\ngetRawPixel\n(*integer* x, *integer* y)\n\n\nReturns the single pixel at the image location (x,y), as an\na *tuple* of *integer*, in the form (a,r,g,b). \n\n##### Arguments\n\n| x | The horizontal position of the pixel, starting with 0 at the left of the screen in the orientation it had when the screenshot was taken. |\n| y | The vertical position of the pixel, starting with 0 at the top of the screen in the orientation it had when the screenshot was taken. |\n|---|------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- A tuple of integers representing the pixel, in the form (a,r,g,b) where a is the alpha channel value, and r, g, and b are the red, green, and blue values, respectively. \n\n#### *tuple*\ngetRawPixelInt\n(*integer* x, *integer* y)\n\n\nReturns the single pixel at the image location (x,y), as an\nan *integer*. Use this method to economize on memory. \n\n##### Arguments\n\n| x | The horizontal position of the pixel, starting with 0 at the left of the screen in the orientation it had when the screenshot was taken. |\n| y | The vertical position of the pixel, starting with 0 at the top of the screen in the orientation it had when the screenshot was taken. |\n|---|------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- The a,r,g, and b values of the pixel as 8-bit values combined into a 32-bit integer, with a as the leftmost 8 bits, r the next rightmost, and so forth. \n\n#### `\n`[MonkeyImage](/tools/help/MonkeyImage)`\n`\ngetSubImage\n(*tuple* rect)\n\n\nCreates a new `MonkeyImage` object from a rectangular selection of the\ncurrent image. \n\n##### Arguments\n\n| rect | A tuple (x, y, w, h) specifying the selection. x and y specify the 0-based pixel position of the upper left-hand corner of the selection. w specifies the width of the region, and h specifies its height, both in units of pixels. The image's orientation is the same as the screen orientation at the time the screenshot was made. |\n|------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- A new `MonkeyImage` object containing the selection. \n\n#### *boolean*\nsameAs\n( `\n`[MonkeyImage](/tools/help/MonkeyImage)`\n` otherImage, *float* percent )\n\n\nCompares this `MonkeyImage` object to another and returns the result of\nthe comparison. The `percent` argument specifies the percentage\ndifference that is allowed for the two images to be \"equal\". \n\n##### Arguments\n\n| other | Another `MonkeyImage` object to compare to this one. |\n| percent | A float in the range 0.0 to 1.0, inclusive, indicating the percentage of pixels that need to be the same for the method to return `true`. The default is 1.0, indicating that all the pixels must match. |\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- Boolean `true` if the images match, or boolean `false` otherwise. \n\n#### void\nwriteToFile\n(*string* filename, *string* format)\n\n\nWrites the current image to the file specified by `filename`, in the\nformat specified by `format`. \n\n##### Arguments\n\n| path | The fully-qualified filename and extension of the output file. |\n| format | The output format to use for the file. If no format is provided, then the method tries to guess the format from the filename's extension. If no extension is provided and no format is specified, then the default format of \"png\" (Portable Network Graphics) is used. |\n|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]