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();
Related
At first, I am converting a PDF file to Image file.
Then I make changes on the Image(converted PDF).
Now, I want to convert everything back to PDF and also have a copy in a base64 format of the PDF.
This is how I convert my PDF:
Future<List<List<int>>> imageFromPdfFileFullImage(
Future<PdfDocument> pdfFile) async {
int height = 0, width = 0;
final document = await pdfFile;
im.Image imImage;
for (int i = 1; i <= document.pagesCount; i++) {
final page = await document.getPage(i);
final pdfPageImage = await page.render(
width: page.width, height: page.height, format: PdfPageFormat.JPEG);
imImage = im.decodeJpg(pdfPageImage.bytes); // First issue in this line
height += imImage.height;
if (imImage.width > width) {
width = imImage.width;
}
//List<Image> buffer 'package:image/image.dart'
imageList.add(imImage);
//List<List<int>> 'package:image/image.dart' as im
//I want this encodeImaegList to be converted back to PDF later
encodeImageList.add(im.encodePng(imageList[i - 1]));
await page.close();
}
return encodeImageList;
}
This may be useful for those who's looking to convert some pdf files to images.
I hope you can help me on my problem too. Thanks guys!
Try this package, hope it helps
https://pub.dev/packages/pdf
I have an image which is being set through:
var oImage = new sap.m.Image({
id: image0,
src: "img/image0.jpg"
});
I want to figure out the width and height of the image ?
I have tried oImage.getWidth() and oImage.getHeight() but those return empty. I have also tried parseInt(oImage.getWidth()) and parseInt(oImage.getHeight()) but those return NaN.
The values are empty because you haven't set them yet. Both getHeight and getWidth return the set values not the default height and width of the image. Have a look at Image Control.
var oImage = new sap.m.Image("image0", {
src: "img/load.gif",
height: "30vh",
width: "30vw"
});
This oImage.getWidth() will return "30vw"
Since, you have not specified with and height of the image, you will have to use the DOM to get the details of the image. Try the following code in your controller:
var image = this.byId("image0");
var oDomRef = image.getDomRef()
console.log(oDomRef .width, oDomRef .height);
It will give the image width and height in px.
I'm trying to load images from internet but i want to show a placeholder till load finishes.
How can i determine the size of placeholder to match the actual size of the image?
The width and height of the image from the api are 2000, 3000 respectively. How can I convert these values?
There are a few parts to the question,
First, you should download an image the from the web through one of many methods.
https://docs.flutter.io/flutter/widgets/FutureBuilder-class.html
https://docs.flutter.io/flutter/widgets/Image/Image.network.html
get the bytes and convert to an image with this https://docs.flutter.io/flutter/widgets/Image/Image.memory.html
Here are the widgets you should use.
You should use this widget as a sized placeholder.
https://docs.flutter.io/flutter/widgets/SizedBox-class.html
Here is a possible child to show a loading animation
https://docs.flutter.io/flutter/material/CircularProgressIndicator-class.html
To display it, you can either complete the FutureBuilder or
Image im = null;
Map imageDimensions = null;
initState(){
fetchImageDimension.fetch().then((imageD) => setState(){imageDimensions = imageD;})
somefuntion.fetch().then((image) => setState(){im = image;})
}
Widget build(buildContext context){
var width = imageDimensions["width"];
var height = imageDimensions["height"];
var placeholderColor = imageDimensions["color"];
var dimensionsLoaded = imageDimensions != null;
var imageLoaded = im != null;
return if(imageLoaded)
Image.....
else {
if(dimensionsLoaded) {
SizedBox(
width: width,
height: height,
child: const Card(child: Container(color: Color(placeholderColor)),
)
} else {
//neigher image or dimensions are Loaded. Nothing you can do
}
}
}
}
This code is not meant to be compiled but it is meant to show the possible options to answer the question.
I tried to use html2canvas to get image screenshot byte from website. However, the screenshot result ended with poor resolution. Looking for advice to improve screenshot quality. Thanks.
How about something like this:
var $wrapper = $("#yourDiv");
setSize($wrapper, "2000px", "20pt");
html2canvas($wrapper, {
onrendered: function (canvas) {
var a = document.createElement('a');
a.href = canvas.toDataURL("image/jpg");
a.download = 'filename.jpg';
a.click();
setSize($wrapper, "1000px", "10pt");
}
});
function setSize(dv, width, fontsize) {
dv[0].style.width = width;
dv[0].style.fontSize = fontsize;
}
This resizes the div and font to bigger size and then shrinks back afterwards.
BMP image is here: https://www.filepicker.io/api/file/fdsYv4NSaCGUefBAQmER
And the code to reproduce the failure:
var fpfile = { url: 'https://www.filepicker.io/api/file/fdsYv4NSaCGUefBAQmER',
filename: 'customers.jpg', mimetype: 'image/jpeg', isWriteable: false, size: 629454};
console.log("Converting...");
/*an element where we can display the resulting image*/
var result = document.getElementById("convert-result");
filepicker.convert(fpfile, {width: 200, height: 200},
function(new_FPFile){
console.log(new_FPFile.url);
result.src = new_FPFile.url;
}
);
Unclear what I am doing wrong here, any help would be most appreciated.
thanks
We don't currently support .bmp's for conversion, but we're in the process of adding it.