Convert base64 string to image in smartface.io - smartface.io

Hello smartface community,
I need help to convert the base64 string back to image in smartface.io.
For example, following code converts image to base64
var img = new SMF.Image(e.file);
var blob = img.getBlob();
var base64StringDataForRegisterImage = blob.toBase64String();
Now I have another page where I am receiving base64 string from webservice but I am not able to convert it to image to assign to image control.
Please assist with the working code to achieve same.
Thanks

You can directly assign your base64 string to the SMF.UI.image object's image property.
Let say you have an image object named imgProfilePic on Page2.
var myBase64StringFromWebservice = (...) // base64 string from your service
var imgProfilePic = new SMF.UI.Image({
top: "20%",
left: "15%",
height: "20%",
width: "70%",
image: myBase64StringFromWebservice,
imageFillType: SMF.UI.ImageFillType.stretch
});
Pages.Page2.add(imgProfilePic);

Related

Print image from API in esc_pos package

image of the image when print
I want to print image in 80mm wifi/printer image come from API as string.
Some of the images print correctly and some do not.
My code:
void testReceipt(NetworkPrinter printer, String img) async {
Uint8List unit8List = base64Decode(img);
Image? a = decodeImage(unit8List);
print(decodeImage(unit8List));
printer.image(a!, align: PosAlign.center);
printer.cut();
}
I Solved it by change the width of the image
Uint8List unit8List = base64Decode(img);
image.Image? a = image.decodeImage(unit8List);
image.Image resized = image.copyResize(a!, width: 600, height: a.height);
printer.image(resized, align: PosAlign.center);
printer.cut();

Is there a quill delta format to html converter for flutter?

Is there a quill delta format to html converter for flutter?
I would like to show my former saved documents in flutter.
What is the proper way?
You can try this to convert.
var QuillDeltaToHtmlConverter = require('quill-delta-to-html').QuillDeltaToHtmlConverter;
// TypeScript / ES6:
// import QuillDeltaToHtmlConverter from 'quill-delta-to-html';
var d_Ops = [
{insert: "Hello world\n"},
{insert: "This is colorful and joyful", attributes: {color: '#f00'}}
];
var config = {};
var converter = new QuillDeltaToHtmlConverter(d_Ops , config );
var html = converter.convert();
Source: https://github.com/nozer/quill-delta-to-html

sapui5:How to display base64 image in Rich text editor?

I created an img element string with base64 source. when tried to display it in sap.ui.richtexteditor.RichTextEditor, I got nothing. How to display it? see my code.
// controller
var template = {};
var image ="<img src="data:image/bmp;base64,/9j/4AAQSkZJRg...">";
template.body = image;
var oViewModel = new JSONModel(template);
this.getView().setModel(oViewModel, "template");
//view
<rte:RichTextEditor id="rte" value="{template>/body}" editorType="TinyMCE4" customToolbar="true" showGroupFont="true" showGroupInsert="true"
showGroupLink="true" height="360px"/>
why dont use the Image Control?
<Image src='data:image/png;base64,iVBORw0KGgoA...........=='/>

How to send large Base64 data to NavController in Ionic 2/3?

I am trying to send Base64 data as string to another page using NavController using below code:
ConvertHTMLToPDF = () => {
let htmlGrid = document.getElementById('customContent');
const options = {background: "white", height: htmlGrid.clientHeight, width: htmlGrid.clientWidth};
html2canvas(htmlGrid, options).then((canvas) => {
let doc = new jsPDF("p", "mm", "a4");
let imgData = canvas.toDataURL("image/PNG");
//Add image Canvas to PDF
doc.addImage(imgData, 'PNG', 20, 20);
let pdfData = doc.output('datauri');
let obj = {PDFSrc: pdfData};
this.navCtrl.setRoot('SaveConsentLetterPage', obj);
});
};
This is perfectly working when the Base64 data is small in size like 3Kb or 4Kb. But, when the data is like 1.2Mb, the NavController can redirect to SaveConsentLetterPage. It crashes the application.
Why is that? Is there any limit to send data with setRoot to another page in Ionic 2/3?
Actually the problem was with below line:
let pdfData = doc.output('datauri');
This opens the data uri/pdfData in current window and as a result, preventing to go the next page.
But, below line returns only the data uri string and as a result, can easily pass the data to next page.
doc.output('datauristring');

save google gauge chart as a png

I am using google charts and have a page of mixed charts, some pie, a column chart and a gauge chart
The page has an option to generate a pdf, so I am converting the charts to PNG to use in the pdf..
all the charts are generated in the same manner, using a div to display the google chart and a hidden div to store the png image
var chart = new google.visualization.Gauge(document.getElementById('gauge'));
var hidden = new google.visualization.Gauge(document.getElementById('gauge_hidden'));
// Wait for the chart to finish drawing before calling the getImageURI() method.
google.visualization.events.addListener(chart, 'ready', function () {
gauge_hidden.innerHTML = '<img src="' + chart.getImageURI() + '">';
});
chart.draw(data, options);
this code works fin on he pie and column charts, but on the gauge chart I am seeing
chart.getImageURI is not a function
any ideas how I can get the png?
CHeers
I was facing this same issue, but after some reading i've come to this solution:
I'm using jQuery to make this a little easier.
First, use XMLSerializer to convert the SVG chart to a string and then use btoa to convert that to base64.
You can use this string this way:
var s = new XMLSerializer().serializeToString($(chart_div).find('svg')[0]);
var base64String = "data:image/svg+xml;base64," + window.btoa(s);
In my case i needed to draw the gauge chart to a PDF and DOMPDF doesn't support this format, so if you need a "data:image/png;base64," string, you can continue with this solution.
You need to set the "svg+xml;base64" as src of a new Image and then draw that image to a Canvas. After that you can use toDataURL method from canvas to get the content as base64 png.
var s = new XMLSerializer().serializeToString($(chart_div).find('svg')[0]);
var image = new Image();
image.width = 640;
image.height = 480;
image.src = 'data:image/svg+xml;base64,' + window.btoa(s);
var myCanvas = document.createElement('canvas');
myCanvas.width = 640;
myCanvas.height = 480;
var myCanvasContext = myCanvas.getContext('2d');
myCanvasContext.drawImage(image,0,0);
// get google chart gague to base64, yey!
var base64String = myCanvas.toDataURL();
Thanks to the author of this answer and this post