|
|
|
|
94
|
if (w <= 0 || h <= 0) {
|
94
|
if (w <= 0 || h <= 0) {
|
95
|
throw new RuntimeException("Impossible to snapshot the view: view is invalid");
|
95
|
throw new RuntimeException("Impossible to snapshot the view: view is invalid");
|
96
|
}
|
96
|
}
|
|
|
97
|
+ if (!view.isDrawingCacheEnabled())
|
|
|
98
|
+ view.setDrawingCacheEnabled(true);
|
|
|
99
|
+
|
97
|
Bitmap bitmap = view.getDrawingCache();
|
100
|
Bitmap bitmap = view.getDrawingCache();
|
98
|
- if (bitmap == null)
|
|
|
99
|
- view.setDrawingCacheEnabled(true);
|
|
|
100
|
- bitmap = view.getDrawingCache();
|
|
|
|
|
101
|
+
|
101
|
if (width != null && height != null && (width != w || height != h)) {
|
102
|
if (width != null && height != null && (width != w || height != h)) {
|
102
|
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
|
103
|
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
|
103
|
}
|
104
|
}
|
|
|
|
|
105
|
throw new RuntimeException("Impossible to snapshot the view");
|
106
|
throw new RuntimeException("Impossible to snapshot the view");
|
106
|
}
|
107
|
}
|
107
|
bitmap.compress(format, (int)(100.0 * quality), os);
|
108
|
bitmap.compress(format, (int)(100.0 * quality), os);
|
|
|
109
|
+ view.setDrawingCacheEnabled(false);
|
108
|
}
|
110
|
}
|
109
|
}
|
111
|
}
|