How can i create block where developer can input a image from assets?

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.

sur @Mohamed_Tamer kindly have a look here

Do you mean an assets image ?
Also, for questions about extension development you should ask in the app Inventor community:

2 Likes

I Am Using Like This Without Any Extra Implement :joy: :joy: :joy: You Can Try

@SimpleFunction(description = "")
public String Get(String img){
String file = "/mnt/sdcard/Makeroid/assets/" + img;
if(file.contains(".jpg")) {
	if (file.exists()) {
		String file = "/mnt/sdcard/Makeroid/assets/" + img;
		
	} else {
		String file = "/mnt/sdcard/AppInventor/assets/" + img;
	}
elseif(file.contains(".png")) {
	if (file.exists()) {
		String file = "/mnt/sdcard/Makeroid/assets/" + img;
		
	} else {
		String file = "/mnt/sdcard/AppInventor/assets/" + img;
	}

}

}
1 Like

That code would work only with the companion :thinking: However, it depends on how @AryanGupta would use it.

2 Likes

Yes It’s Depend On Use It’s Was Just For Example

1 Like

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

i want to get the filePath . just like this event
image

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 :thinking:

1 Like

does this need any import and myAssetName name must include .jpg or .png or not.

and how to use @UsesAssets method

It should include the file extension.

See here:

does kodular support this Annotation

please mention all the imports

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

give me a example