MonkeyImage
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Cihazın veya emülatör ekranının resmini içeren bir monkeyrunner sınıfı. Resim
ekran görüntüsü sırasında ekran arabelleğinden kopyalanmıştır. Bu nesnenin yöntemleri şunları yapmanıza olanak tanır:
resmi çeşitli depolama biçimlerine dönüştürebilir, resmi bir dosyaya yazabilir, resmin parçalarını
ve bu nesneyi diğer MonkeyImage
nesnelerle karşılaştırın.
Yeni MonkeyImage
örnekleri oluşturmanız gerekmez. Bunun yerine
Ekran görüntüsünden yeni bir örnek oluşturmak için
MonkeyDevice.takeSnapshot()
tuşlarına basın. Örneğin, şunu kullanın:
newimage = MonkeyDevice.takeSnapshot()
Özet
Yöntemler |
dize
|
convertToBytes
(dize biçimi)
Mevcut resmi belirli bir biçime dönüştürür ve
dize değerini alır. Bu dize, daha sonra ikili baytların yiterilebilir.
|
tuple
|
getRawPixel
(tam sayı x,
tam sayı y)
Görselin konumundaki (x,y) tek pikseli bir
(a,r, g,b) tam sayı tuple (tuple) değeri.
|
tamsayı
|
getRawPixelInt
(tam sayı x,
tam sayı y)
Görselin konumundaki (x,y) tek pikseli aşağıdaki gibi döndürür:
32 bit tam sayı.
|
MonkeyImage
|
getSubImage
(tuple dikdörtgen)
Dikdörtgen seçiminden yeni bir MonkeyImage nesnesi oluşturur
mevcut resim.
|
boole
|
sameAs
(MonkeyImage
diğer,
kayma yüzdesi)
Bu MonkeyImage nesnesini başka bir nesneyle karşılaştırır ve şunun sonucunu döndürür:
en iyi uygulamaları görelim. percent bağımsız değişkeni yüzdeyi belirtir
iki resmin "eşit" olmasına izin verilen fark.
|
geçersiz
|
WriteToFile
(dize yolu,
dize biçimi)
Mevcut resmi, filename tarafından belirtilen dosyaya yazar
format tarafından belirtilen biçim.
|
Herkese açık yöntemler
Mevcut resmi belirli bir biçime dönüştürür ve dize olarak döndürür
Böylece, ikili baytların yiterilebilir bir öğesi olarak erişebilirsiniz.
Argümanlar
biçim |
İstenen çıkış biçimi. Yaygın olarak kullanılan tüm kafes çıkış biçimleri desteklenir.
Varsayılan değer "png"dir (Taşınabilir Ağ Grafikleri).
|
tuple
getRawPixel
(tam sayı x,
tamsayı y)
Görselin konumundaki (x,y) tek pikseli bir
(a,r, g,b) tam sayı tuple (tuple) değeri.
Argümanlar
x |
Pikselin, ekranın sol tarafındaki 0 ile başlayan ve
ekran görüntüsü alındığında sahip olduğu yönde değişiklik gösterebilir.
|
y |
Pikselin, ekranın üst kısmındaki 0 ile başlayan ve
ekran görüntüsü alındığında sahip olduğu yönde değişiklik gösterebilir.
|
İlerlemeler
-
Pikseli temsil eden, (a,r,g,b) biçiminde bir tam sayı
a alfa kanalı değeri, r, g ve b ise kırmızı, yeşil ve mavi değerleri;
tıklayın.
tuple
getRawPixelInt
(tam sayı x,
tamsayı y)
Görselin konumundaki (x,y) tek pikseli bir
tam sayı. Bellekten tasarruf etmek için bu yöntemi kullanın.
Argümanlar
x |
Pikselin, ekranın sol tarafındaki 0 ile başlayan ve
ekran görüntüsü alındığında sahip olduğu yönde değişiklik gösterebilir.
|
y |
Pikselin, ekranın üst kısmındaki 0 ile başlayan ve
ekran görüntüsü alındığında sahip olduğu yönde değişiklik gösterebilir.
|
İlerlemeler
-
Pikselin a,r,g ve b değerleri, 8 bit değerleri olarak bir 32 bit olarak birleştirilir
bir tam sayı, en soldaki 8 biti içeren bir tam sayı, r en sağdadır ve bu şekilde devam eder.
MonkeyImage
getSubImage
(tuple dikdörtgen)
Dikdörtgen seçiminden yeni bir MonkeyImage
nesnesi oluşturur
mevcut resim.
Argümanlar
rect |
Seçimi belirten bir unsur (x, y, w, h). x ve y 0 tabanlı pikseli belirtir
konumuna getirin. w,
bölge ve h, yüksekliğini her ikisi de piksel cinsinden belirtir.
Resmin yönü, gösterildiği sıradaki ekran yönüyle aynıdır
ekran görüntüsü alındı.
|
İlerlemeler
-
Seçimi içeren yeni bir
MonkeyImage
nesnesi.
boole
sameAs
(
MonkeyImage
diğerResim,
yüzde kayma
)
Bu MonkeyImage
nesnesini başka bir nesneyle karşılaştırır ve şunun sonucunu döndürür:
en iyi uygulamaları görelim. percent
bağımsız değişkeni yüzdeyi belirtir
iki resmin "eşit" olmasına izin verilen fark.
Argümanlar
diğer |
Bu öğeyle karşılaştırılacak başka bir MonkeyImage nesnesi daha.
|
yüzde
|
0,0 - 1,0 dahil olmak üzere, bu değerler dahil olmak üzere
yöntemin döndürülmesi için aynı olması gereken piksellerin yüzdesi
true Varsayılan değer 1,0'dır ve bu değer, tüm piksellerin
eşleşmelidir.
|
İlerlemeler
-
Resimler eşleşirse
true
Boole, aksi takdirde false
Boole değerini döndürür.
Mevcut resmi, filename
tarafından belirtilen dosyaya yazar
format
tarafından belirtilen biçim.
Argümanlar
yol |
Çıkış dosyasının tam dosya adı ve uzantısı.
|
biçim
|
Dosya için kullanılacak çıkış biçimi. Biçim sağlanmazsa
yöntemi, dosya adının uzantısından biçimi tahmin etmeye çalışır. Yanıt hayır ise
uzantısı sağlanmışsa ve herhangi bir biçim belirtilmemişse,
"png" (Taşınabilir Ağ Grafikleri) kullanılır.
|
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-27 UTC.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 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|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]