Application webview Bianliaoge applet now ready to intercept Web Images
But using the Picture pic = webView.capturePicture (); each interception picture is the entire page, and I hope that the interception is a region of the screen, how to adjust the size of the interception area it?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
cutButton.setOnClickListener (new View.OnClickListener ()
{
@ Override
public void onClick (View v)
{
Picture pic = webView.capturePicture ();
int width = pic.getWidth ();
int height = pic.getHeight ();
if (width> 0 && height> 0)
{
Bitmap bmp = Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas (bmp);
pic.draw (canvas);
try
{
String fileName = "sdcard /" + System.currentTimeMillis () + ". Png";
FileOutputStream fos = new FileOutputStream (fileName);
if (fos! = null)
{
bmp.compress (Bitmap.CompressFormat.PNG, 90, fos);
fos.close ();
}
Toast.makeText (getApplicationContext (), "shot is successful, the file name is:" + fileName, Toast.LENGTH_SHORT) show ();
.}
catch (Exception e)
{
e.printStackTrace ();
}
}
}
});
Reply:
/ / Before the game development projects need to consider both adaptive screen then I wrote such a way to create the specified width and height of the picture, the desire to help the landlord.
/ **
* Create a new shrink or enlarge the image
*
* @ Param resources
* @ Param resourcesID
* @ Param scr_width
* @ Param res_height
* @ Return
* /
private Bitmap CreatMatrixBitmap (Bitmap bitMap, float scr_width, float res_height) {
int bitWidth = bitMap.getWidth ();
int bitHeight = bitMap.getHeight ();
float scaleWidth = scr_width / (float) bitWidth;
float scaleHeight = res_height / (float) bitHeight;
Matrix matrix = new Matrix ();
matrix.postScale (scaleWidth, scaleHeight);
bitMap = Bitmap.createBitmap (bitMap, 0, 0, bitWidth, bitHeight, matrix, true);
return bitMap;
}
Reply:
The method capturePicture WebView () itself is copy Content currently displayed, then getWidth, getHeight method to get the width, height, and then createBitmap there is an error. . .
Get the current view of the starting position, width, height, width and height should be the current cell phone fishes ~ ~
Reply:
view.setDrawingCacheEnabled (true);
view.getDrawingCache ();
Interception on the current screen area
Reply:
It's very simple ah ..
Bitmap bmp = Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888);
The width and height settings as you want does not have to
For example
Bitmap bmp = Bitmap.createBitmap (400, 200, Bitmap.Config.ARGB_8888);
Reply:
view.setDrawingCacheEnabled (true);
view.getDrawingCache ();
This method is to get a screenshot of the entire WebView (Content fewer words). If the content is high, pictures can not be generated.
Reply:
This approach is taken in the first half of the image, instead of the current display. How should the currently displayed to take it?
Reply:
If you remove the outer layer of the listening event, let the program run directly intercept the contents of WebView, why complain. . . Show: get width, height is 0. . .
Request advice. . . .
Reply:
Many webview content, after the interception of 5000 pixels, the picture is very vague, a word not see country?
No comments:
Post a Comment