Im grabbing a picture from the gallery like described in the docs. that works, I can pick the pictures in my ios gallery and I am getting a full stream:
string localFilePath = System.IO.Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
MainThread.BeginInvokeOnMainThread(() =>
{
img_profilePic.Source = ImageSource.FromStream(() => localFileStream);
img_profilePic.IsVisible = true;
});
But when I try to set the image to the imagesource of my image from xaml, nothing changes in the UI.
If I change the image to a local image however, it updates the UI. So it must be something with the stream.
Anyone got any idea?
Related
Currently, what I did is to access the camera and use it to take a picture, but this isn't exactly what I want to accomplish.
I want to activate and display front camera preview on my content page, and then take a picture by pressing a button control.
I've searched around and I can't seem to find any solution. In Xamarin, there's CameraView from Xamarin Community Toolkit that can be used for camera stream, but from the looks of it, CameraView hasn't been implemented in .NET MAUI Community Toolkit. Is there any other way to do this? Thank you.
This is the code for the button event
private async void takephoto(object sender, EventArgs e)
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
if (photo != null)
{
// save the file into local storage
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
Stream stream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
DisplayPhoto.Source = ImageSource.FromStream(() =>
{
return stream;
});
}
}
}
I am trying to upload an audio file to firebase within my flutter app.
The user flow is filePicker -> confirm screen (where the user picks the details of the song like name, caption, etc). If I wait too long in the confirm screen (longer than the length of the audio file), the file "times out" and returns false for file.existsSync().
However, whenever I run through the confirm screen super fast, it works because I uploaded it before the length of the audio file finishes. I assume this has to do with caching, but I have no idea how to fix this.
My code for uploading is below:
Future<String> _uploadSongToStorage(String id, String songPath) async {
Reference ref = firebaseStorage.ref().child('songs').child(id);
//assert(songFile.existsSync());
UploadTask uploadTask = ref.putFile(File(songPath));
TaskSnapshot snap = await uploadTask;
String downloadUrl = await snap.ref.getDownloadURL();
return downloadUrl;}
I want to create an image picker like android native that detect all available applications to pick image using flutter image picker.
To be more specific I want to display the available image applications.
Hey Don't know about image_picker, but file_picker works for me as below
Future getFromGallery() async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(type: FileType.image);
if (result != null) {
setState(() {
pickedImage = File(result.files.single.path!);
});
}
}
How can I convert a PDF file into an image with Flutter?
I want to print the image to an ESC/POS printer using esc_pos_printer. This package won't accept PDFImage, it needs to be a Flutter Image.
I see plenty of PHP plugins that do this but nothing for Flutter.
edit: There is an answer to another question here which shows some code to decode an image from "pdf64" but I can't figure out exactly what "pdf64" is.
I created a PDF from html using flutter_html_to_pdflike this:
Directory appDocDir = await getApplicationDocumentsDirectory();
var targetPath = appDocDir.path;
var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent(
htmlContent, targetPath, targetFileName);
generatedPdfFilePath = generatedPdfFile.path;
Now I need to know how to create a Flutter Image from that PDF or the bytecode to send raw to the printer.
You can use https://pub.dev/packages/printing:
await for (var page in Printing.raster(document)) {
final image = page.asImage();
...
}
This plugin can also convert your Html to Pdf with this:
final pdf = await Printing.convertHtml(
format: PdfPageFormat.a4,
html: '<html><body><p>Hello!</p></body></html>',
));
I'm trying to do some pre-processing in my image before using Firebase MLkit. Previously, I was simply loading my image and then passing it directly like this.
File file = await FilePicker.getFile(type: FileType.IMAGE);
final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(file);
VisionText visionText = await textRecognizer.processImage(visionImage);
But now, I wanted to do some processing on the image. I did this using Flutter's Image package like this.
import 'package:image/image.dart' as Img;
File file = await FilePicker.getFile(type: FileType.IMAGE);
Img.Image image = Img.decodeImage(file.readAsBytesSync());
var img = Img.invert(image);
Now, how do I pass this new object to FirebaseVisionImage. I see that there is this function:
FirebaseVisionImage.fromBytes(bytes, metadata)
I'm guessing I can get bytes from the above image object using img.getBytes() but I'm confused how to set the metadata.
EDIT:
I see that one can write the image to a temporary file doing
img.writeAsBytesSync(decoded.ToList());
and then use that image again using FirebaseVisionImage.fromFile() but I would really prefer not to do that.