Problem with imageview

All your problems with Audio, Video and Images.

Problem with imageview

Postby jonbonazza » Thu Jul 15, 2010 3:43 pm

Ok, I have a function in my app that fetches an image from an FTP server and then sets it as the source of an image view.

According to my FTPServer's log, it transfers perfectly fine, but when it sets it as the imageView's source, it is just a white image (At least I am assuming it is white.. my background is white and there is no iamge there, so...). It is doing something to the imageview though because I have an initial image setup so I know when it has been changed.

Here is my function:

Code: Select all
private Bitmap downloadImage(String filename)
   {   
      InputStream iStream = null;
      byte[] buffer = null;
      int bufferSize = 0;
      try
      {
         iStream = ftp.retrieveFileStream(filename);
         bufferSize = iStream.read(buffer);
         image = BitmapFactory.decodeByteArray(buffer, 0, buffer.length);
      }
      catch(Exception e)
      {
         Log.i("debug", "Failade to retrieve file...");
      }
      return image;
   }



secondly, I have the following thread:
Code: Select all
public class connectionThread implements Runnable
   {
      connectionThread()
      {
         
      }
      
      public void run()
      {
         FTPConnect();
         
         connectionHandler.sendEmptyMessage(0);
         image = downloadImage(ROTM_IMAGE_NAME);
         downloadHandler.sendEmptyMessage(0);
      }
   }


and lastly, I have the following Handler:
Code: Select all
private Handler downloadHandler = new Handler()
   {
      @Override
      public void handleMessage(Message msg)
      {
         pDialog.dismiss();
         rotm.setImageBitmap(image);
      }
   };


The only thing I can thing of (but unsure how to rememdy it if it is the case) would be that "image" is being returned to the connectionThread thread and when I call rotm.setImageBitmap(image);, it just sets the image to null since it hasn't been initialized int he main thread...
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Re: Problem with imageview

Postby blundell » Thu Jul 15, 2010 8:48 pm

Just on a side note, you would want the image variable in downloadImage() to be a local variable within the method.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Problem with imageview

Postby jonbonazza » Mon Jul 19, 2010 7:10 pm

blundell wrote:Just on a side note, you would want the image variable in downloadImage() to be a local variable within the method.


Thanks for the tip, but since image would be accessed elsewhere in the code, wouldn't I want to declare it globaly (as a private variable) and then be able to access it everywhere else? if I make it a local variable, then it won't be able to be accessed from outside the downloadImage() method, right? Though I guess I could keep instantiating it in different places in the code... which would be a better approach?

Also, I figured it out... I was using the streams incorrectly.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Problem with imageview

Postby blundell » Mon Jul 19, 2010 9:34 pm

But your method return's 'image' so yes you would have a global, but you would instantiate that global by calling this method. Otherwise you would just get confused.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Problem with imageview

Postby jonbonazza » Mon Jul 19, 2010 9:38 pm

blundell wrote:But your method return's 'image' so yes you would have a global, but you would instantiate that global by calling this method. Otherwise you would just get confused.


Ohh. I see what you are saying... Yea, that probably would be better...
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 17 guests