mirror of
https://github.com/gsantner/dandelion
synced 2024-11-16 01:12:08 +01:00
screenshot cature -> replaced capturePicture (deprecated)
This commit is contained in:
parent
88801f6961
commit
2955c67783
1 changed files with 62 additions and 31 deletions
|
@ -32,7 +32,7 @@ import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Picture;
|
import android.graphics.Paint;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
@ -86,6 +86,7 @@ import org.json.JSONException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -630,23 +631,38 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||||
Picture picture = webView.capturePicture();
|
|
||||||
Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
|
webView.measure(View.MeasureSpec.makeMeasureSpec(
|
||||||
Canvas c = new Canvas(b);
|
View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
|
||||||
File screen = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/"
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
|
||||||
+ dateFormat.format(date) + ".jpg");
|
webView.layout(0, 0, webView.getMeasuredWidth(),
|
||||||
if (screen.exists())
|
webView.getMeasuredHeight());
|
||||||
screen.delete();
|
webView.setDrawingCacheEnabled(true);
|
||||||
picture.draw(c);
|
webView.buildDrawingCache();
|
||||||
FileOutputStream fos = null;
|
Bitmap bm = Bitmap.createBitmap(webView.getMeasuredWidth(),
|
||||||
|
webView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
|
Canvas bigcanvas = new Canvas(bm);
|
||||||
|
Paint paint = new Paint();
|
||||||
|
int iHeight = bm.getHeight();
|
||||||
|
bigcanvas.drawBitmap(bm, 0, iHeight, paint);
|
||||||
|
webView.draw(bigcanvas);
|
||||||
|
System.out.println("1111111111111111111111="
|
||||||
|
+ bigcanvas.getWidth());
|
||||||
|
System.out.println("22222222222222222222222="
|
||||||
|
+ bigcanvas.getHeight());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fos = new FileOutputStream(screen);
|
OutputStream fOut;
|
||||||
if (fos != null) {
|
File file = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/", dateFormat.format(date) + ".jpg");
|
||||||
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
|
fOut = new FileOutputStream(file);
|
||||||
fos.close();
|
|
||||||
}
|
bm.compress(Bitmap.CompressFormat.PNG, 50, fOut);
|
||||||
|
fOut.flush();
|
||||||
|
fOut.close();
|
||||||
|
bm.recycle();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.getMessage();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
|
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
|
||||||
sharingIntent.setType("image/png");
|
sharingIntent.setType("image/png");
|
||||||
|
@ -693,23 +709,38 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||||
Picture picture = webView.capturePicture();
|
|
||||||
Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
|
webView.measure(View.MeasureSpec.makeMeasureSpec(
|
||||||
Canvas c = new Canvas(b);
|
View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
|
||||||
File screen = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/"
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
|
||||||
+ dateFormat.format(date) + ".jpg");
|
webView.layout(0, 0, webView.getMeasuredWidth(),
|
||||||
if (screen.exists())
|
webView.getMeasuredHeight());
|
||||||
screen.delete();
|
webView.setDrawingCacheEnabled(true);
|
||||||
picture.draw(c);
|
webView.buildDrawingCache();
|
||||||
FileOutputStream fos;
|
Bitmap bm = Bitmap.createBitmap(webView.getMeasuredWidth(),
|
||||||
|
webView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
|
Canvas bigcanvas = new Canvas(bm);
|
||||||
|
Paint paint = new Paint();
|
||||||
|
int iHeight = bm.getHeight();
|
||||||
|
bigcanvas.drawBitmap(bm, 0, iHeight, paint);
|
||||||
|
webView.draw(bigcanvas);
|
||||||
|
System.out.println("1111111111111111111111="
|
||||||
|
+ bigcanvas.getWidth());
|
||||||
|
System.out.println("22222222222222222222222="
|
||||||
|
+ bigcanvas.getHeight());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fos = new FileOutputStream(screen);
|
OutputStream fOut;
|
||||||
if (fos != null) {
|
File file = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/", dateFormat.format(date) + ".jpg");
|
||||||
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
|
fOut = new FileOutputStream(file);
|
||||||
fos.close();
|
|
||||||
}
|
bm.compress(Bitmap.CompressFormat.PNG, 50, fOut);
|
||||||
|
fOut.flush();
|
||||||
|
fOut.close();
|
||||||
|
bm.recycle();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.getMessage();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
File file = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/"
|
File file = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/"
|
||||||
+ dateFormat.format(date) + ".jpg");
|
+ dateFormat.format(date) + ".jpg");
|
||||||
|
|
Loading…
Reference in a new issue