Android Picture Object in ImageView anzeigen

  • Antworten:2
Gelöschter Account
  • Forum-Beiträge: 4

04.05.2011, 11:05:23 via Website

Hallo Liebe Androidler .

Ich hab ein kleines Problem das ich einfach nicht lösen kann.
Vielleicht hat ja jemand eine Lösung parat.

Folgendes: Ich möchte ein Screenshot von einer WebView machen und diesen dann in einer ImageView anzeigen.

Mein Code im Moment:

1WebView mWebView = new WebView(this);
2mWebView.getSettings().setJavaScriptEnabled(true);
3mWebView.loadUrl("http://www.google.de");
4
5Picture picture = mWebView.capturePicture();
6Bitmap b = Bitmap.createBitmap( picture.getWidth(),
7picture.getHeight(), Bitmap.Config.ARGB_8888);
8Canvas c = new Canvas( b );
9picture.draw( c );
10
11ImageView imgv= (ImageView) findViewById(R.id.webView1);
12imgv.setDrawingCacheEnabled(true);
13imgv.draw(c);
14Paint paint= new Paint();
15c.drawBitmap(b, 0, 0, paint);


-------------------------------------------------
alternativ:
1WebView mWebView = new WebView(this);
2 mWebView.getSettings().setJavaScriptEnabled(true);
3 mWebView.loadUrl(item.getUrl());
4 mWebView.setWebViewClient(new mediaWebViewClient());
5 Picture picture = mWebView.capturePicture();
6 Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
7 Canvas c = new Canvas(b);
8 picture.draw(c);
9 View view = (View)findViewById(R.id.webView1);
10 view.draw(c);

--------------------------------------------------------------------

Beides Funktioniert leider nicht so wie erhofft, gibt immer eine Exception
Danke schon mal im Voraus.
--------------------------------------------------------------------

Exception:
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): FATAL EXCEPTION: main
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.app/android.app.mediaAItemView}: java.lang.IllegalArgumentException: width and height must be > 0
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.os.Looper.loop(Looper.java:144)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.ActivityThread.main(ActivityThread.java:4937)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at java.lang.reflect.Method.invoke(Method.java:521)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at dalvik.system.NativeStart.main(Native Method)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): Caused by: java.lang.IllegalArgumentException: width and height must be > 0
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.graphics.Bitmap.nativeCreate(Native Method)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.graphics.Bitmap.createBitmap(Bitmap.java:574)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.mediaAItemView.onCreate(mediaAItemView.java:133)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
05-04 10:54:26.333: ERROR/AndroidRuntime(11913): ... 11 more

--------------------------------------------------------------------
Mir ist auch klar das widht and height größer 0 sein müssen!!!!
--------------------------------------------------------------------
Hat jemand eine Lösung für das Problem??

Grüße,
Javacode

— geändert am 04.05.2011, 11:21:18

Antworten
Frank W.
  • Forum-Beiträge: 5.103

04.05.2011, 11:12:06 via Website

Hallo Javacode! Erstmal Herzlich willkommen bei uns. :lol:

Ich verschieb mal ins Entwickler-Forum. Für besere Lesbarkeit kannst du deinen Code auch in einen Code-Block packen. Das ist das Icon genau neben den Smilies, wenn du einen Post erstellst oder editierst.

Frank

"Irgendwann, möglicherweise aber auch nie, werde ich dich bitten, mir eine kleine Gefälligkeit zu erweisen." (Don Corleone) Für ein friedliches Miteinander"

Antworten
Gelöschter Account
  • Forum-Beiträge: 4

04.05.2011, 11:20:25 via Website

Dankeschön!

Antworten