yes i need it as @AryanGupta said
oh yeah
is there any more good code like @Mohamed_Tamer
I’m confused why @Mohamed_Tamer code doesn’t work
@SimpleFunction(description = "")
public void pick(AndroidViewComponent layout, String imagePath) throws Exception {
InputStream in;
try{
in = container.$form().openAssetForExtension(imagePath);
} catch (IOException e) {
} finally {
in.close();
}
Bitmap bmp = BitmapFactory.decodeStream(in);
Image img = (Image) bmp;
setImage(img);
}
@SimpleEvent
public void setImage(Image img) {
//dispatch the event
}
use this code. i just add IOException.
@DevYB sur, your code is not working. it store nothing in in
InputStream.
it gives me a error - in.close on a null object reference
This may help you to directly get image(bitmap) from any path or asset
MediaUtil.getBitmapDrawable(form, imageURI).getBitmap();
yeah I think using MediaUtil is a better way
@Atom_Developer what’s wrong with my code?
@SimpleFunction(description = "")
public void pick(AndroidViewComponent layout, String imageURI) {
Drawable drawable = MediaUtil.getBitmapDrawable(container.$form(), imageURI).getBitmap();
View view = layout.getView();
view.setImageDrawable(drawable);
}
Error :
AndroidRuntime:
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/salmanappinventor/Testaix/Testaix.java:55: error: incompatible types: Bitmap cannot be converted to Drawable
[javac] Drawable drawable = MediaUtil.getBitmapDrawable(container.$form(), imageURI).getBitmap();
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/salmanappinventor/Testaix/Testaix.java:57: error: cannot find symbol
[javac] view.setImageDrawable(drawable);
[javac] ^
[javac] symbol: method setImageDrawable(Drawable)
[javac] location: variable view of type View
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors
[javac] 1 warning
so you cannot use this .
Drawable drawable =MediaUtil.getBitmapDrawable(container.$form(), imageURI).getBitmap();
use this something like that
Bitmap drawable =MediaUtil.getBitmapDrawable(container.$form(), imageURI).getBitmap();
Code To Get Drawable
Drawable drawable =MediaUtil.getBitmapDrawable(container.$form(), imageURI);
actually I love drawable more than Bitmap
btw, you can convert the bitmap to drawable. using this method
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
but it is easy to use @Atom_Developer code. Go for it
@Salman_Dev What Do You Exactly Want To Do Otherwise This Game May Be Played To A Month Or Year
What are you talking about
I Means What Do You Exactly Want To Do ?
Q1. Do You Want User Input Name Of Assets Image And Show It In Given Arrangement As A Background ?
Q2. Do You Want User Input Name Of Assets Image And Show It In Given Arrangement With Image ?
Q3. Or Do You Just Want To Pass The Name Of Assets And User Can Set It In ImageView Component That’s In Build
I Want User Input Name Of Assets Image And Show It In all type components