AryanGupta
(Aryan Gupta)
November 28, 2020, 11:08am
1
i am trying to create a block where we can input a image and return it as path.
what i have tried
@SimpleProperty(
category = PropertyCategory.ASSET)
public void Picture(String image) {
return picturePath;
}
i want to get the image path and store it in a variable.
AryanGupta
(Aryan Gupta)
November 28, 2020, 11:24am
2
sur @Mohamed_Tamer kindly have a look here
AryanGupta:
image
Do you mean an assets image ?
Also, for questions about extension development you should ask in the app Inventor community:
2 Likes
Srrazmi
(Web And App Developer)
November 28, 2020, 12:55pm
4
1 Like
That code would work only with the companion However, it depends on how @AryanGupta would use it.
2 Likes
Srrazmi
(Web And App Developer)
November 28, 2020, 1:04pm
6
Yes It’s Depend On Use It’s Was Just For Example
1 Like
AryanGupta
(Aryan Gupta)
November 28, 2020, 1:06pm
7
i only want to input a image from assets and set the image of a component .
You can use openAssetForExtension method which would return an InputStream from the assets name :
InputStream in;
try{
in = container.$form().openAssetForExtension(this, "myAssetName.png");
} finally {
in.close();
}
NOTE: this code would work only when using UsesAssets annotation. If you want to open any file from the app assets use:
AssetManager am = context.getAssets();
InputStream in = am.open("myAssetName.png");
And then you can use BitmapFactory class to decode this inputStream into a Bitmap:
Bitmap bmp = BitmapFactory.decodeStream(in);
Now you can set your image image to this bitmap:
image.getView().setImageBitmap(bmp); // you need get the imageView from the Image.
5 Likes
AryanGupta
(Aryan Gupta)
November 28, 2020, 1:26pm
9
i want to get the filePath . just like this event
AryanGupta
(Aryan Gupta)
November 28, 2020, 1:36pm
10
sur @Mohamed_Tamer please give me a reply
You would need to copy the assets to the external storage if you need to return the path to the user, however, you can get its input stress described above and use it with your extension
1 Like
AryanGupta
(Aryan Gupta)
November 28, 2020, 1:55pm
12
does this need any import and myAssetName name must include .jpg or .png or not.
AryanGupta
(Aryan Gupta)
November 28, 2020, 2:06pm
13
and how to use @UsesAssets method
It should include the file extension.
AryanGupta
(Aryan Gupta)
November 28, 2020, 2:09pm
16
does kodular support this Annotation
AryanGupta
(Aryan Gupta)
November 28, 2020, 2:12pm
17
please mention all the imports
AryanGupta
(Aryan Gupta)
November 28, 2020, 2:13pm
18
and what does bmp returns
Yes, the form class.
As far I know yes, as it’s used in the maps component.
It’s a Bitmap