Android :: Loading & Displaying Image From A Resource
Apr 29, 2010
Currently I'm successfully loading and displaying an image from a webserver using the code below.
URL imgURL = new URL("http://www.xxx.com/myimage.png"); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm= BitmapFactory.decodeStream(bis); bis.close(); is.close();
canvas.drawBitmap(bm, 0, 0, null);
What I want to do is load it from a resource. I've put myimage.png into res/drawable and referenced the bitmap as follows :-
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);
However when I try to display it with canvas.drawBitmap(bm, 0, 0, null); I get a Force Close. What am I missing?
View 2 Replies
May 4, 2009
I want to display a fancy 'loading' image at my app's startup time.
The problem: my startup code is mostly GUI related, hence needs to run on UI thread.
Is there a way to do both - that is run UI-related code on UI thread while an image is displayed to the user?
View 8 Replies
View Related
Jul 21, 2010
I use http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012 to load images in a ListView and a GridView. It works but the images are loaded form bpttom to top. How to fix that?
Bonus Question: Can I use a loading animation in a image view while the real image is loaded? Right now it's just a default image.
View 1 Replies
View Related
Sep 5, 2010
I'm trying to find a way to open resources which name is determined at runtime only. Let me explain in more details. I want to have a XML that references a bunch of other XML files in the application apk. for the purpose of explaining lets say the main XML is main.xml and the other XML are file1.xml file2.xml...fileX.xml...
what i want is to read main.xml, extract the name of the xml I want (fileX.xml) for example. and then read fileX.XML. the problem I face is that what I extract form main.xml is a string and I can't find a way to change that to R.raw.nameOfTheFile
View 2 Replies
View Related
Jan 20, 2009
My application needs to load and process some data at the startup which delays the displaying of the GUI quite a bit. I addressed that problem by starting a new thread to load and process the data. It solves the problem nicely, but is there a better way to do asynchronous processing in Android applications that I missed?
View 2 Replies
View Related
Sep 11, 2010
I am loading a bitmap from a resource like so:
Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image);
What I want to do is make some changes to the bitmap before It gets drawn to the main canvas in my draw method (As it would seem wasteful to repeat lots of drawing in my main loop when it isn't going to change). I am making the changes to the bitmap with the following:
Canvas c = new Canvas(mBackground);
c.drawARGB(...); // etc
So naturally I get an exception
java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
So to avoid that I made a copy of the bitmap so that it is mutable
Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image).copy(Bitmap.Config.ARGB_8888, true);
Which avoid the problem however it sometimes causes OutOfMemoryExceptions, do know any better ways of achieving what I want?
View 2 Replies
View Related
Nov 6, 2010
I want to load resource that is located in android.R.attr class.Next code failed to load resource with Resources$NotFoundException exception:
getResources().getString(android.R.attr.action); //action is a string resource
Also tried to load resource using:
getResources().obtainAttributes(android.R.attr.action)
No exception is thrown, but returned TypedArray array has nothing valuable inside it. At least I couldn't find anything that is connected to actual resource id or resource I'm interested in.So, how to load resources represented by android.R.attr.* ids?
View 1 Replies
View Related
Jan 6, 2010
I want to show a loading Image of GIF type for a finite time .how to do this. Please tell me the solution if anyone knows.
View 3 Replies
View Related
Sep 15, 2010
I use this method couples of occasion to load text file to display as help file. But I don't know why the following code didn't work. It seems to hang and logcat says "OutOfMemoryError"? All I did was break this out as an separate activity.
---xml---
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/helptab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/helptext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
---code---
import java.io.DataInputStream;
import java.io.IOException; import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Help extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
InputStream iFile = getResources().openRawResource(R.raw.help);
try { TextView helpText = (TextView) findViewById(R.id.helptext);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
} }
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = "";
while ((strLine = dataIO.readLine()) != "") {
sBuffer.append(strLine + " ");
} dataIO.close();
is.close();
return sBuffer.toString();
}
View 6 Replies
View Related
Oct 13, 2010
Are there any Android phones that are multi-processor (multi-core/ cpu), where application threads execute concurrently on different processors?
There doesn't seem to be any explicit way of doing asynchronous file I/ O or asynchronous resource loading. So, suppose I put BitmapFactory.decodeResource() or Resources.openRawResource() into a separate thread. Will those methods play nice with the other threads, yielding during blocking I/O operations so those other threads can run?
If those methods rely on the thread scheduler to forcibly suspend them, then the separate resource-loading thread isn't going to help me get my application started any faster (although it will help it to be more responsive to user input).
View 5 Replies
View Related
Apr 29, 2010
All I want to do is display a URL image. Does anyone have a template I could use that already displays an image that I can possibly modify? I've been looking all over the internet and the only answers I've found are extremely complex.I'm very good at learning something once I can get it to work from my end then proceed to analyzing the code.I am VERY new at Android programming.
View 5 Replies
View Related
Jun 15, 2010
How can i get the resource id of an image if i know its name (in android)
View 1 Replies
View Related
Aug 19, 2010
I have a Main class with has onCreate() method. in that method i have made the MapFile class' object.and called its readFile() and readIndex() methods. in readIndex() method i call another class named MapTile where i read the images tiles from my binary file and there i have to display my image.now question is how can i display image without putting my code into onCreate(Bundle savedInstanceStare) method.i am trying this way but on first line it gives me null pointer exception.
ImageView image = (ImageView) findViewById(android.R.id.icon); Bitmap bMap = BitmapFactory.decodeByteArray(imageTile, 0, imageTile.length);image.setImageBitmap(bMap);
View 1 Replies
View Related
Sep 7, 2010
I want to download image from distant server and use it as resource. Is it possible ? How can I do this ?
View 2 Replies
View Related
Mar 23, 2009
I'm trying to display an image using a URL. When I run the code I get an error telling me the application has stopped unexpectedly. Can anyone see what's wrong in my code.
Bitmap bmImg; URL myFileUrl =null; try {
myFileUrl= new URL("http://www.starling-fitness.com/wp-content/ 240384vBdA_w.jpg");
} catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace();
} try { URLConnection conn= (URLConnection)myFileUrl.openConnection();
conn.setDoInput(true); conn.connect(); int length = conn.getContentLength();
int[] bitmapData = new int[length]; byte[] bitmapData2 = new byte[length];
InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is);
/*timetableImage.setImageBitmap(bmImg);*/ setContentView(R.layout.timetable);
ImageView iv = (ImageView)findViewById(R.id.timetableImage); iv.setImageBitmap(bmImg);
} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
}
View 4 Replies
View Related
Nov 7, 2010
I'm creating a simple application for Android which should display an image which is located on remote HTTP server. Which is the best way to do this: should it write the image to some temporary file, or just load it to RAM (in this case, how to load image to ImageView from byte array)?
View 1 Replies
View Related
Feb 1, 2010
I draw 2d images on the canvas using the following tutorial.
http://www.designerandroid.com/?cat=3
I want to save what ever displaying in a canvas as a jpg image, how can i do it?
View 1 Replies
View Related
Jul 23, 2010
I am using following code to capture image through camera and then displaying it.
The problem , I am facing is when i take picture and press done button it does not display that taken image in my activity.
It just shows blank image field.
CODE:....................
View 2 Replies
View Related
Jun 23, 2010
I'm wondering..
1)is it possible to set an imageview's resource to the URL location of an image?
2)is there a way of setting the x,y co-ords of where on the screen to draw the imageview?
3)How would I run a check to see if the space is taken up by another Imageview (must specifically be an imageview)
4) How would I make the Imageview "clickable" e.g if the user clicks the image it'll do something?
5) How would I dynamically create imageviews? E.g if a condition is true make another imageview
Perhaps I'm going about this wrong so I'll explain better what I'm looking to do.. basically I want to draw images on the screen which are located at URL's. I want to display N amount of images (There will be conditions which will decide how many images I'm displaying, so it'll have to be dynamically created) each image should take up approx 50x50 screen space. There will be other conditions to where the image should be displayed.. If an image exists at a certain co-ord it shouldn't draw over it, when the user clicks the image something else should happen.
View 1 Replies
View Related
Sep 8, 2009
I am using a GridView. It contains images. When I click on any item of this grid view I want this image Resource ID to be sent to another activity. Where can I display this image in larger size?
How can I get Image Resource ID and send it to other activity?
View 2 Replies
View Related
May 24, 2009
I want to use the ninepatch image in the file system. but seems that it can be referenced via res.
how to get the auto-scale support for the images in file system.
View 2 Replies
View Related
Jan 7, 2010
So here's the problem. I am displaying a big image in ImageView and need to find it's position relative to the image.
View 2 Replies
View Related
May 2, 2010
I am trying to create a drawable in code and change the color based on some criteria. When I try and set the Drawable as the background of the ImageView it displays but won't let me set any padding. I realized I need to set the ImageView image via the setImageDrawable() function in order to be able to set the padding. The problem I am running into is that when I set it via the setImageDrawable() function nothing is displayed.
Here is what I have written:
<?xml version="1.0" encoding="utf-8"?>
ImageView icon = (ImageView) row.findViewById(R.id.icon);
ShapeDrawable mDrawable; int x = 0; int y = 0;
int width = 50; int height = 50;
float[] outerR = new float[] { 12, 12, 12, 12, 12, 12, 12, 12 };
mDrawable = new ShapeDrawable(new RoundRectShape(outerR, null, null));
mDrawable.setBounds(x, y+height, x + width, y);
switch(position){ case 0: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 1: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 2: mDrawable.getPaint().setColor(0xff00c000); //Green break;
case 3: mDrawable.getPaint().setColor(0xff00c000); //Green break;
case 4: mDrawable.getPaint().setColor(0xff0000ff); //Blue break;
case 5: mDrawable.getPaint().setColor(0xff0000ff); //Blue break;
case 6: mDrawable.getPaint().setColor(0xff696969); //Gray break;
case 7: mDrawable.getPaint().setColor(0xff696969); //Gray break;
case 8: mDrawable.getPaint().setColor(0xffffff00); //Yellow break;
case 9: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 10: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 11: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 12: mDrawable.getPaint().setColor(0xffa020f0); //Purple break;
case 13: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 14: mDrawable.getPaint().setColor(0xffffd700); //Gold break;
case 15: mDrawable.getPaint().setColor(0xffff6600); //Orange break;
} icon.setImageDrawable(mDrawable); icon.setPadding(5, 5, 5, 5);
This results in a space for the ImageView but no image.
View 1 Replies
View Related
Sep 30, 2010
This one surely is a simple one but I haven't made sense of is yet. I'm working on an app in opengl es on android. everything goes well except when I load the textures. I manage to open load and create all the textures without any problem, but the image displays itself rotated of 90. it looks as if the application does not consider that its is in landscape when opening the image...I solved the problem by turning all my textures of 90 degrees but I would sure like to figure this one out Because it is the only thing that is not rotated, the top bar is rotated, the touch coordinated are rotated,
the h and w of the surface are good,
Here are some code snippets that I think are relevant:
CODE:...........
View 1 Replies
View Related
Aug 6, 2009
Does setImageResource() in ImageView also draws the image instantly on the screen or does it require any other function call? i need to display the image as soon as i set the resource.
View 7 Replies
View Related
Oct 27, 2010
I looked at the 2 examples on Stack, but can't get them to work. I'm simply trying to grab an image from a folder in assets and set it as in ImageView, but get a null pointer returned.
Main Activity:
CODE:...........
And my two xml files:
CODE:...........
Also tried this, but still get a file not found exception.
CODE:.......................
View 1 Replies
View Related
Apr 19, 2010
Set the image background path as package:imageName Example. At runtime , my package is com.test.android .Inside that i have an image whose path i want to mention in the XML layout file as android:src = com.test.android/img1 for an ImageButton.I saw an SDK reference for ImageView as android:src = @[+][package:]type:name.But i am not getting how to use it.I think it must not be possibe , but if there is any way , please specify.The reason why i want to do this is that,when i specify a drawable at runtime for my image buttons, i change the images according to Focus received, or onKeyup, KeyDown.. but its not working as expected.When i mention the same thing as style under drawable, it works fine. So if my theme is going to change at runtime, i want to set the drawable at runtime, keepnig the path same in the xml.
View 2 Replies
View Related
Dec 8, 2009
On the G1 camera app, there's a handsome looking camera button which you can press to signal the app to take the picture. It's a round button with a little camera icon in it. Is that button resource available in android.R? I'd like to use it in my own app if possible?
View 2 Replies
View Related
Aug 11, 2009
I'm trying to set the background of a webview to a drawable image resource in Android.From the sdk it seems something like this would work but it doesn't.
View 5 Replies
View Related
Sep 27, 2010
I am new in android devlopment
i want to know how to upload an image in android
i don't found any useful tutorial for this
can u give me some instruction.
View 3 Replies
View Related