Android Zooming For Graphs - android

I need to implement zoom functionality for graphs which are retrieving from web. These graphs are from php web-server so how to implement zooming functionality to these graphs. Any one can help me to come out from this issue. This is my java class code for retriving graphs from web.
localPalladium1YButton.setOnClickListener( new View.OnClickListener() {
public void onClick(View view)
{
localPalladium1DButton.setBackgroundResource(R.drawable.onedicon);
localPalladium5DButton.setBackgroundResource(R.drawable.fived);
localPalladium1MButton.setBackgroundResource(R.drawable.whitem);
localPalladium1YButton.setBackgroundResource(R.drawable.yover);
android.view.View.OnClickListener getImgListener = null;
localPalladium1YButton.setOnClickListener(getImgListener);
Bitmap palladiumBitmap3=fetchImage( PalladiumImageUrl4.trim() );
localPalladiumImageView.setImageBitmap( palladiumBitmap3 );
mSoundManager.playSound(1);
}
});
..................................
..................................
..................................
Bitmap bmImg;
void downloadFile(String fileUrl){
URL myFileUrl =null;
try {
myFileUrl= new URL(fileUrl);
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
String url1 = "my url";
URL url = new URL(url1);
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
BitmapFactory.Options bf = new BitmapFactory.Options();
Bitmap bm = BitmapFactory.decodeStream(bis);
ImageView localGoldImageView = null;
localGoldImageView.setImageBitmap(bm);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Bitmap fetchImage( String urlstr )
{
try
{
URL url;
url = new URL( urlstr );
HttpURLConnection c = ( HttpURLConnection ) url.openConnection();
c.setDoInput( true );
c.connect();
InputStream is = c.getInputStream();
Bitmap img;
img = BitmapFactory.decodeStream( is );
return img;
}
catch ( MalformedURLException e )
{
Log.d( "RemoteImageHandler", "fetchImage passed invalid URL: " + urlstr );
e.printStackTrace();
}
catch ( IOException e )
{
Log.d( "RemoteImageHandler", "fetchImage IO exception: " + e );
e.printStackTrace();
}
return null;
}
Thanks,
Murali.

Take a look at http://code.google.com/p/android-pinch/: it has code to implement zooming using pinch.

Related

Image not showing on image view

I am trying to set image on imageview but image is not show.
I am reading image url from json data and then trying to set it on ImageView but my image is not visible. No any exception occur.
Here is my code
HotelList.class
static final String TAG_DISHIMAGEURL = "dishimageurl";
......
String imageUrl = dishResult.getString(TAG_DISHIMAGEURL);
map.put(TAG_DISHIMAGEURL, imageUrl);
.....
dishimageurl1 = hm.get(TAG_DISHIMAGEURL).toString();
intent.putExtra("background", dishimageurl1);
HotelDetails.class
......
String dishimageurl = bundle.getString("background");
Bitmap bimage= getBitmapFromURL(dishimageurl);
imageView.setImageBitmap(bimage);
....
public Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
Toast.makeText(this, "showing image", Toast.LENGTH_LONG).show();
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
Toast.makeText(this, "showing exception", Toast.LENGTH_LONG).show();
return null;
}
}
I don't understand what happen with this code. No any exception but my image is not visible.
Please give me any reference.
Please Use below code for get image from url and display into imageview.
public class image extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bitmap = DownloadImage("http://www.gophoto.it/view.php?i=http://1.bp.blogspot.com/-2LTvCCufBKc/T3L3KgcTj2I/AAAAAAAABbQ/Ki60e1LU9sE/s1600/Sachin%2BTendulkar.png");
RelativeLayout mRlayout1 = (RelativeLayout) findViewById(R.id.mRlayout1);
Drawable d=new BitmapDrawable(bitmap);
mRlayoutLogin.setBackgroundDrawable(d);
}
private InputStream OpenHttpConnection(String urlString) throws IOException {
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (Exception ex) {
throw new IOException("Error connecting");
}
return in;
}
private Bitmap DownloadImage(String URL) {
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
}
}
you can view image by using this code.
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
It seems you are downloading the image from UI thread. this will block the UI thread and will give you not responding error. as an easy way, you can use a library like Universal Image Loader
Universal Image Loader - GitHub
this will manage the image loading for you and avoid problems like incorrect urls, Out Of Memory error.

how to parse the image which is in very big size?

i am using json parsing in my url a very big size images are there and i want get those images but not downloaded .....can any body help me to get those images
my code is as followsenter code here
public class Image extends Activity{
String imageBaseDirectory = "http://www.dha.com.tr/newpics/news/";
Bitmap bit;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
ImageView img=(ImageView)findViewById(R.id.ImageView01);
img.setImageBitmap(convertImage(imageBaseDirectory));
}
public Bitmap convertImage(String s)
{
URL aURL = null;
try
{
final String imageUrl =s.replaceAll(" ","%20");
Log.e("Image Url",imageUrl);
aURL = new URL(imageUrl);
URLConnection conn = aURL.openConnection();
InputStream is = conn.getInputStream();
//#SuppressWarnings("unused")
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(new PatchInputStream(bis));
if(bm==null){}
else
bit=Bitmap.createScaledBitmap(bm,60, 60, true);
return bit;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
Try this code I hope it will help.
private Bitmap LoadPhotoFromServer(String path){
Bitmap bm=null;
URL url = null;
try {
url = new URL(path);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
HttpURLConnection httpConnection=(HttpURLConnection)url.openConnection();
httpConnection.setDoInput(true);
httpConnection.connect();
//int lengthOfFile=httpConnection.getContentLength();
InputStream inputStream=httpConnection.getInputStream();
bm=BitmapFactory.decodeStream(inputStream);
}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bm;
}

Show Avatar Facebook to ImageView

I used the code as follows to show up facebook avatar to ImageView
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img = (ImageView) findViewById(R.id.imgAvatar);
img.setImageBitmap(getBitmapFromURL("http://graph.facebook.com/"+"100002394015528"+"/picture"));
}
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}`
But does it not work. Please help me.
http://graph.facebook.com/id/picture doesn't return an image. It returns some response headers including a 302 redirect, and a location header.
Your example for instance redirects to: http://profile.ak.fbcdn.net/hprofile-ak-snc4/211619_100002394015528_568817_q.jpg
So instead of
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
You need to get the headers from the request, follow the location and then do what you were doing before. I don't know Android, or what language that is. (Java?) So I can't help with that, but I think this might be enough information to get you headed in the right direction.
Use this function for get real URL to avatar:
public static String getUrlFacebookUserAvatar(String name_or_idUser )
{
String address = "http://graph.facebook.com/"+name_or_idUser+"/picture";
URL url;
String newLocation = null;
try {
url = new URL(address);
HttpURLConnection.setFollowRedirects(false); //Do _not_ follow redirects!
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
newLocation = connection.getHeaderField("Location");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return newLocation;
}

I am not getting image from url by using this code

I am using the following code
public class Img extends Activity {
/** Called when the activity is first created. */
ImageView img;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView)findViewById(R.id.imgview);
Bitmap bm = getBitmapFromURL("http://l.yimg.com/a/i/us/we/52/21.gif");
if(bm == null)
Toast.makeText(this, "Image can't load", 1).show();
else
img.setImageBitmap(bm);
}
public static Bitmap getBitmapFromURL(String src) {
try {
Log.e("src",src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
Log.e("Bitmap","returned");
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
Log.e("Exception",e.getMessage());
return null;
}
}
}
I am getting a message "Image can't load"
Please try below code.
ImageView img;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView)findViewById(R.id.imgview);
Drawable image = getBitmapFromURL("http://l.yimg.com/a/i/us/we/52/21.gif");
if(image == null)
Toast.makeText(this, "Image can't load", 1).show();
else
img.setImageDrawable(image);
}
public Drawable getBitmapFromURL(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
try this..
private Bitmap downloadUrl(String url) {
InputStream myInputStream =null;
Bitmap myBitmap;
StringBuilder sb = new StringBuilder();
//adding some data to send along with the request to the server
sb.append("name=Anthony");
URL url;
try {
url = new URL(url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStreamWriter wr = new OutputStreamWriter(conn
.getOutputStream());
// this is were we're adding post data to the request
wr.write(sb.toString());
wr.flush();
myInputStream = conn.getInputStream();
wr.close();
myBitmap = BitmapFactory.decodeStream(myInputStream);
} catch (Exception e) {
//handle the exception !
Log.d(TAG,e.getMessage());
}
return myBitmap;
}

Unable to retrieve the image of https format for facebook in android?

I am trying to get images from facebook using following method. I'm getting an error "SSL denied". I got the image urls from the facebook API. The image urls are of facebook profile pictures.
ImageView image=(ImageView)view.findViewById(R.id.iView);
String imageurl=https://graph.facebook.com/100000685876576/picture;
Drawable drawable=LoadImageFromWebOperations(imageurl);
image.setImageDrawable(drawable);
private Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
//Log.e("DEMO ADAPTER",e.toString());
return null;
}
}
can anyone help me out...
Thanks.
try this
public static Bitmap downloadfile(String fileurl)
{
Bitmap bmImg = null;
URL myfileurl =null;
try
{
myfileurl= new URL(fileurl);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
try
{
HttpURLConnection conn=
(HttpURLConnection)myfileurl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
if(length>0)
{
int[] bitmapData =new int[length];
byte[] bitmapData2 =new byte[length];
InputStream is = conn.getInputStream();
BitmapFactory.Options options = new
BitmapFactory.Options();
options.inSampleSize = 1;
bmImg = BitmapFactory.decodeStream(is,null,options);
}
else
{
}
}
catch(IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return bmImg;
}

Categories

Resources