javaFX webView showing inaccurate rendering - javafx

Here are 2 screenshots so you can understand what am talking about ,
this example shows the rendering of ( www.google.com ) in my app and on chrome so you can see the differences.
My App Rendering
Chrome regular Rendering
As you can see , the rendering inside my App is not as ( responsive ) as it is on chrome.
it seems that only ( google.com ) looks this weird , i have tested wikipedia and facebook , Youtube also , they all rendered perfectly.
this the Code I have written if it helps :
#Override
public void initialize(URL location, ResourceBundle resources) {
webBoot = new WebView();
final WebEngine webEngine = webBoot.getEngine();
webEngine.load("http://www.google.com");
borderPane.setCenter(webBoot);
}

Related

Xamarin Forms: WebView loading time is very high

I am using WebView for loading websites in my project. It is loading websites but very slow. It takes around 10 to 15 seconds to load this site.
I try a solution from this thread. I have added android:hardwareAccelerated="true" on the manifest under application level, but no luck.
For iOS and Windows the solution is below: But I don't know how to create the custom render.
In iOS, try to use WKWebView instead of UIWebView.
For the UWP, use Windows.UI.Xaml.Controls.WebViewcontrol instead of using the built-in Xamarin WebView control.
Can I get the sample custom renderer for iOS and Windows-like above?
It is loading websites but very slow
The speed of loading website will up to lots of causes . For example, it will consume a lot of time if the web contains many remote css/js file . And it will also up to network performance .
The link that you provided loads slow even if on browser on my side . It contains lots of remote css if we check the source code.
For Android , We can create an custom renderer webview to accelerate it.
Set Render Priority to hight.
Enable the dom storeage.
When Loading the html, we can disable the image showing, when
loading finished, load the image by
Control.Settings.BlockNetworkImage.
Enable the Cache, if you load it at the nexttime, you can load it
quickly.
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(MyWebviewRender))]
namespace MyWebviewDemo.Droid
{
public class MyWebviewRender : WebViewRenderer
{
public MyWebviewRender(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
Control.Settings.JavaScriptEnabled = true;
Control.Settings.SetAppCacheEnabled(true);
Control.Settings.CacheMode = Android.Webkit.CacheModes.Normal;
Control.Settings.SetRenderPriority(RenderPriority.High);
Control.Settings.DomStorageEnabled = true;
Control.Settings.BlockNetworkImage = true;
Control.SetWebChromeClient(new MyWebChromeClient());
}
}
internal class MyWebChromeClient : WebChromeClient
{
public override void OnProgressChanged(Android.Webkit.WebView view, int newProgress)
{
base.OnProgressChanged(view, newProgress);
if (newProgress == 100)
{
// webview load success
// // loadDialog.dismiss();
view.Settings.BlockNetworkImage=false;
}
else
{
// webview loading
// loadDialog.show();
}
}
}
}
In iOS, try to use WKWebView instead of UIWebView. For the UWP, use Windows.UI.Xaml.Controls.WebViewcontrol instead of using the built-in Xamarin WebView control.
In your case it will only have less improve even if using above solution . You could add an ActivityIndicator during the loading . If you can access the website , it would be better to download the css file to local and loading them in ContentPage .

CefSharp WpfControl and rendering to image

We want to show a webpage in a chromium based browser within a wpf application.
The website that is displayed within the browser should also be shown on another screen but without interaction.
I want to combine the cefsharp wpf browser control and the cefsharp offscreen rendering.
Can I use one chromium instance for displaying the page with interactions in wpf and export the current visible website as an image?
Thank you and best regards,
Simon
Thank you amatiland, it indeed works with the OnPaint Method or Event.
public MainWindow()
{
InitializeComponent();
Browser.Paint += Browser_Paint;
}
void Browser_Paint(object sender, CefSharp.Wpf.PaintEventArgs e)
{
Bitmap newBitmap = new Bitmap(e.Width, e.Height, 4 * e.Width, System.Drawing.Imaging.PixelFormat.Format32bppRgb, e.Buffer);
var aPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "TestImageCefSharpQuant.png");
newBitmap.Save(aPath);
}
XAML
<wpf:ChromiumWebBrowser x:Name="Browser" Address="www.google.com"></wpf:ChromiumWebBrowser>

RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap

I have a card view which has a custom adapter and it loads image into its target using Picasso(inside onBindViewHolder(lazy load) ).
The custom row has a button on which when clicked opens fragment which displays image in wide view , Using the bitmap from original imageview
( before in fragment i check if bitmap is loaded fully in main imageview using a boolean in callback of Picasso to 'true' in onSucess() . till then my button is disabled ) like :
BindViewHolder:
Picasso.with(context)
.load(cl.getUrlPhoto())
.resize(500, 500)
.error(R.drawable.images)
.into(cardViewHolder.urlPhoto, new Callback() {
#Override
public void onSuccess() {
cardViewHolder.imgL=true;
cardViewHolder.fab.setEnabled(true);
cardViewHolder.pb_b.setVisibility(View.INVISIBLE);
}
#Override
public void onError() {
cardViewHolder.imgL=false;
cardViewHolder.fab.setEnabled(false);
cardViewHolder.pb_b.setVisibility(View.GONE);
}
});
(i check here for the boolean to be true then do this part of code )Fragment part where it loads :
imageView.buildDrawingCache(true);
Bitmap bitmap = imageView.getDrawingCache(true);
BitmapDrawable bitmapDrawable = (BitmapDrawable)
imageView.getDrawable();
bitmap1 = bitmapDrawable.getBitmap();
scaleImageView.setImageBitmap(bitmap1);
. But Sometimes on scrolling when the images are still loading or loaded or just clicking to view full image 2-3 times it crashes and gives error
" RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap . "
This exception is raised in situations where you try to recycle or set to null an image which is loaded by Picasso which means the Picasso library does not expect the image loaded by it to be recycled and when it tries to load that an exception is thrown. hope this solution works for you
Try replacing Picasso with Glide

Make JavaFx application Fullscreen OnClick

Hello i am making a web browser in javafx and i want to make it fullscreen when user clicks on Fullscreen button. I tried the below given code but unfortunately it is giving error.
Fullscreen.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
primaryStage.setFullScreen(true); // here it gives error "cannot find variable primaryStage"
}
});
**I know that this doesn't follow the basics of java but i didn't find another way of implementing it.
Kindly help :)
Assuming Fullscreen is a button, just get the stage it's in with
((Stage)Fullscreen.getScene().getWindow()).setFullScreen(true);

QWebView and downloading of pdf files on genome browser

I am working on a Qt project (Java). I am trying to build a qwebview that allows me to download pdf files from a website.
Here is the code I used:
public Browser() {
this.setDefaultUrl();
this.page().setForwardUnsupportedContent(true);
this.page().unsupportedContent.connect(this,"download()");
}
public void setUrl(String url){
this.load(new QUrl(url));
}
public void setDefaultUrl(){
this.load(new QUrl("http://genome.ucsc.edu/cgi-bin/hgGateway"));
}
public void download(){
System.out.println("Ok");
}
If I click on "We still provide postscript files: browser graphic and ideogram" the signal shoots correctly but if I click on "Download the current browser graphic in PDF" I don't get any signal. Is this because pdf files must be handled differently?
Any ideas why?
Thanks a lot in advance

Resources