regarding Image Viewer

Put your problem here if it does not fit any of the other categories.

regarding Image Viewer

Postby saty_32016 » Thu Mar 13, 2008 6:07 am

Hi Folks,

i am new to this .please help,I stuck some where.image is not displaying in my code.Here is code what i wrote.

IamgeViewer file
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Com.TechM.ImageViewer;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.graphics.Bitmap;
  8.  
  9. import android.graphics.BitmapFactory;
  10.  
  11. import android.graphics.Matrix;
  12.  
  13. import android.graphics.drawable.BitmapDrawable;
  14.  
  15. import android.os.Bundle;
  16.  
  17. import android.widget.ImageView;
  18.  
  19. import android.widget.LinearLayout;
  20.  
  21. import android.widget.ImageView.ScaleType;
  22.  
  23. import android.widget.LinearLayout.LayoutParams;
  24.  
  25.  
  26.  
  27. public class ImageViewer extends Activity {
  28.  
  29.     /** Called when the activity is first created. */
  30.  
  31.     @Override
  32.  
  33.     public void onCreate(Bundle icicle) {
  34.  
  35.         super.onCreate(icicle);
  36.  
  37.         LinearLayout linLayout = new LinearLayout(this);
  38.  
  39.         Bitmap bitmapf = BitmapFactory.decodeResource(getResources(),
  40.  
  41.                         R.drawable.android_118);
  42.  
  43.         int width = bitmapf.width();
  44.  
  45.         int height = bitmapf.height();
  46.  
  47.         int newWidth = 200;
  48.  
  49.         int newheight = 200;
  50.  
  51.        
  52.  
  53.         float scaleWidth = ((float)newWidth)/width;
  54.  
  55.         float scaleHeight = ((float)newheight)/height;
  56.  
  57.        
  58.  
  59.         Matrix matrix = new Matrix();
  60.  
  61.         matrix.postScale(scaleWidth,scaleHeight);
  62.  
  63.         matrix.postRotate(45);
  64.  
  65.        
  66.  
  67.         Bitmap bitmapResize = Bitmap.createBitmap(bitmapf, 0, 0, width, height, matrix, true);
  68.  
  69.         BitmapDrawable bmd = new BitmapDrawable(bitmapResize);
  70.  
  71.         ImageView imageView = new ImageView(this);
  72.  
  73.         imageView.setImageDrawable(bmd);
  74.  
  75.         imageView.setScaleType(ScaleType.CENTER);
  76.  
  77.         linLayout.addView(imageView,
  78.  
  79.                         new LinearLayout.LayoutParams(
  80.  
  81.                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
  82.  
  83.                       )
  84.  
  85.               );
  86.  
  87.  
  88.  
  89.            
  90.  
  91.         setContentView(R.layout.main);
  92.  
  93.     }
  94.  
  95. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


main.xml file

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:orientation="vertical"
  7.  
  8.    android:layout_width="fill_parent"
  9.  
  10.    android:layout_height="fill_parent"
  11.  
  12.    >
  13.  
  14.  
  15.  
  16.  <ImageView android:id="@+id/android_118"
  17.  
  18.   android:layout_width="wrap_content"
  19.  
  20.   android:layout_height="wrap_content"
  21.  
  22.   android:tint="#FF000000"
  23.  
  24.   android:src="@drawable/android_118"/>
  25.  
  26.  
  27.  
  28.    
  29.  
  30.    
  31.  
  32. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4



what else i need to work out?
saty_32016
Developer
Developer
 
Posts: 27
Joined: Mon Mar 10, 2008 4:47 am

Top

Postby kiran » Thu Mar 13, 2008 6:17 am

Hi,

Do you want to display using program or .xml. With the .xml file you have given all you need to do is to call setContentView(R.layout.main); inside onCreate() method.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package Com.TechM.ImageViewer;
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.os.Bundle;
  9.  
  10. import android.widget.ImageView;
  11.  
  12.  
  13.  
  14. public class ImageViewer extends Activity {
  15.  
  16.     /** Called when the activity is first created. */
  17.  
  18.     @Override
  19.  
  20.     public void onCreate(Bundle icicle) {
  21.  
  22.         super.onCreate(icicle);
  23.  
  24.         setContentView(R.layout.main);
  25.  
  26.     }
  27.  
  28. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
:) smile it is the key that fits the lock of everybody's heart
User avatar
kiran
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Thu Nov 22, 2007 11:36 am
Location: India

not even getting image

Postby saty_32016 » Thu Mar 13, 2008 7:52 am

kiran wrote:Hi,

Do you want to display using program or .xml. With the .xml file you have given all you need to do is to call setContentView(R.layout.main); inside onCreate() method.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Com.TechM.ImageViewer;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.widget.ImageView;
  6.  
  7. public class ImageViewer extends Activity {
  8.     /** Called when the activity is first created. */
  9.     @Override
  10.     public void onCreate(Bundle icicle) {
  11.         super.onCreate(icicle);
  12.         setContentView(R.layout.main);
  13.     }
  14. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


hi,
i tried both type but image is not displaying on emulator.
now i have just added my xml file ,your suggested java code and in drwable i put android_118.png.
but still this image is not display any thing on emulator.
if you have any idea please suggest how can i display image and even edit it.

Thanks
Satyendra
saty_32016
Developer
Developer
 
Posts: 27
Joined: Mon Mar 10, 2008 4:47 am

Postby kiran » Thu Mar 13, 2008 8:07 am

Hi,
just tested your code above. first it was showing a black area in the size of the image. Removed the
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:tint="#FF000000"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
line in main.xml and the image is displayed correctly.
:) smile it is the key that fits the lock of everybody's heart
User avatar
kiran
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Thu Nov 22, 2007 11:36 am
Location: India

Postby saty_32016 » Thu Mar 13, 2008 8:47 am

kiran wrote:Hi,
just tested your code above. first it was showing a black area in the size of the image. Removed the
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:tint="#FF000000"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
line in main.xml and the image is displayed correctly.


Hi kiran,

Thanks a lot . it works.got image on emulator in both way (java code and xml ).

Thanks
satyendra Thakur
saty_32016
Developer
Developer
 
Posts: 27
Joined: Mon Mar 10, 2008 4:47 am

Postby Rahul » Tue Oct 14, 2008 11:28 am

Can any one explain me what is happening in these lines

Code: Select all
Bitmap bitmapf = BitmapFactory.decodeResource(getResources(),
               R.drawable.android_118);


Code: Select all
<ImageView android:id="@+id/android_118"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/android_118"/>


what is r.drawable.android_118 ?

where can i locate the drawable folder in an emulator?
Rahul
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am

Top

Postby goelsvaibhav » Thu Oct 30, 2008 7:46 am

Rahul wrote:Can any one explain me what is happening in these lines

Code: Select all
Bitmap bitmapf = BitmapFactory.decodeResource(getResources(),
               R.drawable.android_118);


Code: Select all
<ImageView android:id="@+id/android_118"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/android_118"/>


what is r.drawable.android_118 ?

where can i locate the drawable folder in an emulator?


Hi,

In R.drawable.android_118, android_118 is an image file which is to be placed in drawable folder. The method/any reference gets the image file from the path referred and paints as per the conditions specified.

drawable folder can be located as <project>/res/drawable/ in IDE.

Regards,
Vaibhav
goelsvaibhav
Junior Developer
Junior Developer
 
Posts: 19
Joined: Fri Oct 17, 2008 7:07 am
Location: Gurgaon, India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 24 guests