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

A example of what? However, you can’t actually return a Bitmap.

1 Like

getting a error at this in = openAssetForExtension(image);

error - cannot find symbol

here is my imports

import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.*;

I’ve updated my post half an hour ago to fix this error :slightly_smiling_face:

1 Like

does i need to import form class

Yes you have.

@SimpleFunction
public void SetupView(AndroidViewComponent layout, String image) throws Exception {
try{
in = container.$form().openAssetForExtension(this, image);
} catch (IOException e) {
} finally {
in.close();
}

it gives me an error
Attempt to invoke in.close(); on a null object reference

hope you solve this error soon @Mohamed_Tamer

If you want to open a file from assets, you can try this:
InputStream inputStream = container.$form().openAsset(image);

1 Like

@DevYB how to connect your code with @SimpleEvent

i have already tell you that you can pass the inputStream to @SimpleEvent

Is it like this :

@SimpleFunction
    public void pick(String imagePath) {
       InputStream inputStream = container.$form().openAsset(imagePath);
       AfterPicking(inputStream);
    }
  
    @SimpleEvent
    public void AfterPicking(String imagePath) {     
      EventDispatcher.dispatchEvent(this, "AfterPicking", imagePath);
    }
1 Like

yes, your code should work fine

okay i wil try

You can’t pass an inputStream to a SimpleEvent

so what should i do?

:thinking:

why do you need to pass inputStream

I don’t know, but my goal is I want to get image From Asset and put it in the imageview app inventor, but put it using @SimpleEvent

then, you can use @Mohamed_Tamer code

you need to convert inputStream to Bitmap and then set image view’s image

but how do I get the image using @SimpleEvent
Like this:
image