How to get Image from its native path? - iphone

I have store native path of image file to database. Now I need to display that image. For this I am using
imageView.image = Titanium.Filesystem.getfile(rows.fieldByName('path'));
But no effect.
it is giving error as
[ERROR] invalid image type. expected either TiBlob or TiFile, was: NSNull in -[TiUIImageView setImage_:] (TiUIImageView.m:679)
Please suggest.

I'd say it was because the database value you are returning is a string and not the actual image. Doesn't work like specifying an image path for the web. Try this:
var img_src = Ti.Filesystem.getFile(rows.fieldByName('path'));
var img = img_src.read();
imageView.image = img;

You can give native path in image attribute
var u_image = Titanium.UI.createImageView({
image: rows.fieldByName('path'),
top:10,
left:10,
height:20,
width:20
});
This may help you!!!

Related

Flutter - How to convert Image to List<Int>?

I want to make the following code work and I do not understand image conversion properly. Would really like someone to point me the right direction to learn this please along with providing a solution to my following problem.
I display the image as a container background image using:
MemoryImage(base64Decode(image)) // My image is in base64 String format here
The above works fine.
Now I have an image path: example-
'/data/user/0/....../cache/scaled_image_picker2751194612758734223.jpg'
How do I go from getting image from this path to base64Encode(image)?
I tried the following up to now and have run out of ideas here:
final Image? image = await Image.file(File(_imagePath));
if (image != null){
setState(() => imageDisplayInContainer = base64Encode(image)); <----Doesn't work
}
Get the file object:
File imageFile = File(_imagePath);
Get the bytes:
List<int> imageBytes = imageFile.readAsBytesSync();
Give the bytes the MemoryImage
MemoryImage(imageBytes);

Flutter - Drawstring on captured photo from camera

I am using this https://github.com/brendan-duncan/image/wiki to try and draw text on my image my question is how do I get the image needed for the first parameter in Image.drawString() when the image I am trying to pass is the one that is captured by the camera plugin?
final path = join(
// Store the picture in the temp directory.
// Find the temp directory using the `path_provider` plugin.
(await getTemporaryDirectory()).path,
'${DateTime.now()}.png',
);
// Attempt to take a picture and log where it's been saved.
await _controller.takePicture(path);
//this doesnt work
img.Image image = Image.file(File(path))
img.drawString(image, img.arial_24, 50, 50, "Hello World");
I am getting this error:
'Image (where Image is defined in
myflutterpath/packages/flutter/lib/src/widgets/image.dart)' can't be
assigned to a variable of type 'Image (where Image is defined in
/myflutterpath/flutter/.pub-cache/hosted/pub.dartlang.org/image-2.1.4/lib/src/image.dart)'
You're assigning an Image widget from Flutter to a img.Image variable from the image package. These are completely separate data types.
To do what you want, you need to create an img.Image object. Since your image source is a PNG file(guessing based on file extension), you'll need to decode it to raw pixel data. This can be done with the PngDecoder that's already included in the image package that you have.
img.Image image = img.PngDecoder().decodeImage(await File(path).readAsBytes());
This creates an img.Image from your PNG file instead of an Image widget.

Getting FirebaseVisionImage from manipulated image in Flutter

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.

cn1 - get file path to image for share()

I'm trying to use the share() method, including an image, but I'm having trouble supplying the proper path to the image. Where should I put the image file, and what is the path (putting in the default package and trying "jar:///myimage.png" didn't work), and why is this not documented clearly?
image can be stored in storage which is following path for window
C:\Users\userName.cn1
and the image can be read by using following codes
InputStream is = Storage.getInstance().createInputStream("tizbn.JPG");
EncodedImage i = EncodedImage.create(is, is.available());
Loading image from default folder
Image i =EncodedImage.create("/tizbn.png");
Loading image From Theme
EncodedImage current = (EncodedImage) fetchResourceFile().getImage("tizbn.png");
The share API works with https://www.codenameone.com/javadoc/com/codename1/io/FileSystemStorage.html[FileSystemStorage] and not with https://www.codenameone.com/javadoc/com/codename1/io/Storage.html[Storage].
You need to save the file into a file system path which is always an absolute path, we recommend using the app home to store files. There is a sample in the developer guide section on the ShareButton covering this:
Form hi = new Form("ShareButton");
ShareButton sb = new ShareButton();
sb.setText("Share Screenshot");
hi.add(sb);
Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight());
hi.revalidate();
hi.setVisible(true);
hi.paintComponent(screenshot.getGraphics(), true);
String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png";
try(OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile)) {
ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1);
} catch(IOException err) {
Log.e(err);
}
sb.setImageToShare(imageFile, "image/png");

Showing a lock screen image using MPNowPlayingInfoCenter doesn't work

I have the following code and is working for me but it can only currently show artist and song :
let mpic = MPNowPlayingInfoCenter.defaultCenter()
mpic.nowPlayingInfo = [MPMediaItemPropertyTitle:songs[currentAudioIndex].songName,
MPMediaItemPropertyArtist:songs[currentAudioIndex].artistName]
I tried also setting the picture with the following code but it isn't working :
mpic.nowPlayingInfo = [MPMediaItemPropertyTitle:songs[currentAudioIndex].songName,
MPMediaItemPropertyArtist:songs[currentAudioIndex].artistName,
MPMediaItemPropertyArtwork:songs[currentAudioIndex].songImage]
SongImage is of type UIImage.
Never mind I figured out.
If anyone want to learn you have to
do the following
let mpic = MPNowPlayingInfoCenter.defaultCenter()
// initialize an instance of MPMediaItemArtWork with a UIImage
var albumArtWork = MPMediaItemArtwork(image: songs[currentAudioIndex].songImage)
// Then assign it to the MPNowPlayingInfoCenter
mpic.nowPlayingInfo = [
MPMediaItemPropertyTitle:songs[currentAudioIndex].songName,
MPMediaItemPropertyArtist:songs[currentAudioIndex].artistName,
MPMediaItemPropertyArtwork:albumArtWork
]
Hope this helps anyone who is also struggling with this.
Thanks
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [MPMediaItemPropertyArtist : AudioCenter.sharedInstnce.currentReciter().name,
MPMediaItemPropertyTitle : AudioCenter.sharedInstnce.currentSurah()!.name,
MPMediaItemPropertyArtwork:MPMediaItemArtwork(image: UIImage(named: "Logo")!)]