Help on Resizing of the image

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

Help on Resizing of the image

Postby Tanuja » Thu Nov 20, 2008 8:34 am

Hi .....
i am facing problem in the resizing of the image. i have created the image and now want to maximize the size of the image ontouch.... i.e., wherever i click the mouse on the image... the image should get enlarge......
help me out.........

Thanks and regards
Tanuja
Tanuja
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Oct 30, 2008 7:13 am

Top

Postby MrSnowflake » Thu Nov 20, 2008 1:50 pm

There are several ways to do this:
- Using animations
- Scaling the image in onDraw() using a matrix
- Scaling the actuall image
- ...
Vote for your favorite! ;)
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Tanuja » Fri Nov 21, 2008 5:47 am

Actually ... what i want is .... when i click the mouse on the image.... after the release that part of image shuold enlarge...... i am not getting how to do it........ please help me.........

Thanks and regards
Tanuja
Tanuja
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Oct 30, 2008 7:13 am

Postby Danuubz » Mon Nov 24, 2008 2:49 pm

Taking ImageView-approach might fit good for this purpose. An ImageView automatically scales the Image to his own size. Therefore, if you change the size of the ImageView, you also change the size of your image.

If you want to enlarge only a part of an image, that will be more work :wink:

Example code (insert image of your choice, named 'pic', into the 'res/drawable' folder):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package de.flippertest;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.graphics.*;
  8.  
  9. import android.graphics.drawable.*;
  10.  
  11. import android.os.Bundle;
  12.  
  13. import android.widget.*;
  14.  
  15. import android.widget.LinearLayout.LayoutParams;
  16.  
  17. import android.widget.ZoomControls;
  18.  
  19. import android.graphics.*;
  20.  
  21. import android.graphics.drawable.*;
  22.  
  23. import android.view.*;
  24.  
  25. import android.view.GestureDetector.OnGestureListener;
  26.  
  27. import android.content.res.*;
  28.  
  29. import android.content.*;
  30.  
  31.  
  32.  
  33. public class FlipperTest extends Activity
  34.  
  35. {
  36.  
  37.         private AbsoluteLayout main;
  38.  
  39.         private MyImageView imgView;
  40.  
  41.         private Bitmap image;
  42.  
  43.        
  44.  
  45.     @Override
  46.  
  47.     public void onCreate(Bundle savedInstanceState)
  48.  
  49.     {
  50.  
  51.         super.onCreate(savedInstanceState);
  52.  
  53.         getBmp();
  54.  
  55.         makeGUI();
  56.  
  57.     }
  58.  
  59.    
  60.  
  61.     private void makeGUI()
  62.  
  63.     {
  64.  
  65.         main = new AbsoluteLayout(this);
  66.  
  67.         main.setLayoutParams(new LinearLayout.LayoutParams(320,480));
  68.  
  69.         main.setBackgroundColor(Color.WHITE);
  70.  
  71.        
  72.  
  73.         imgView = new MyImageView(this);
  74.  
  75.         imgView.setLayoutParams(new AbsoluteLayout.LayoutParams(80,80,50,50));
  76.  
  77.         imgView.setImageBitmap(image);
  78.  
  79.        
  80.  
  81.         main.addView(imgView);
  82.  
  83.        
  84.  
  85.         setContentView(main);
  86.  
  87.     }
  88.  
  89.    
  90.  
  91.     private void getBmp()
  92.  
  93.     {
  94.  
  95.         Resources res = this.getResources();
  96.  
  97.         image = BitmapFactory.decodeResource(res, R.drawable.pic);
  98.  
  99.     }
  100.  
  101.    
  102.  
  103.     class MyImageView extends ImageView implements OnGestureListener
  104.  
  105.     {
  106.  
  107.         public static final int SMALL = 0;
  108.  
  109.         public static final int LARGE = 1;
  110.  
  111.        
  112.  
  113.         private int size = SMALL;
  114.  
  115.        
  116.  
  117.         private GestureDetector gesture;
  118.  
  119.        
  120.  
  121.         private int smallX = 80;
  122.  
  123.         private int smallY = 80;
  124.  
  125.         private int largeX = 140;
  126.  
  127.         private int largeY = 140;
  128.  
  129.        
  130.  
  131.         public MyImageView(Context context)
  132.  
  133.         {
  134.  
  135.                 super(context);
  136.  
  137.                 gesture = new GestureDetector(this);
  138.  
  139.         }
  140.  
  141.        
  142.  
  143.         @Override
  144.  
  145.             public boolean onTouchEvent(MotionEvent me)
  146.  
  147.             {
  148.  
  149.                 gesture.onTouchEvent(me);
  150.  
  151.                
  152.  
  153.                 return true;
  154.  
  155.             }    
  156.  
  157.        
  158.  
  159.         @Override
  160.  
  161.             public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
  162.  
  163.             {
  164.  
  165.                 return true;
  166.  
  167.             }
  168.  
  169.            
  170.  
  171.             @Override
  172.  
  173.             public boolean onDown(MotionEvent e)
  174.  
  175.             {
  176.  
  177.                 return true;
  178.  
  179.             }
  180.  
  181.            
  182.  
  183.             @Override
  184.  
  185.             public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
  186.  
  187.             {          
  188.  
  189.                 return true;
  190.  
  191.             }
  192.  
  193.            
  194.  
  195.             @Override
  196.  
  197.             public void onLongPress(MotionEvent e)
  198.  
  199.             {  
  200.  
  201.                
  202.  
  203.             }
  204.  
  205.            
  206.  
  207.             @Override
  208.  
  209.             public void onShowPress(MotionEvent e) {   }    
  210.  
  211.            
  212.  
  213.             @Override
  214.  
  215.             public boolean onSingleTapUp(MotionEvent e)    
  216.  
  217.             {    
  218.  
  219.                 if(size == SMALL)
  220.  
  221.                 {
  222.  
  223.                         imgView.setLayoutParams(new AbsoluteLayout.LayoutParams(largeX,largeY,50,50));
  224.  
  225.                         main.invalidate();
  226.  
  227.                        
  228.  
  229.                         size = LARGE;
  230.  
  231.                 }
  232.  
  233.                 else if(size == LARGE)
  234.  
  235.                 {
  236.  
  237.                         imgView.setLayoutParams(new AbsoluteLayout.LayoutParams(smallX,smallY,50,50));
  238.  
  239.                         main.invalidate();
  240.  
  241.                        
  242.  
  243.                         size = SMALL;
  244.  
  245.                 }
  246.  
  247.                
  248.  
  249.                 return true;
  250.  
  251.             }          
  252.  
  253.     }
  254.  
  255. }
  256.  
  257.  
Parsed in 0.044 seconds, using GeSHi 1.0.8.4
User avatar
Danuubz
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Wed Dec 19, 2007 10:44 pm
Location: Germany

Postby dkkundudolan » Wed Nov 26, 2008 7:50 am

Hi danuubz,

I want to change the color of the Image.
Here in the 1st page i have the Image, textView and Button in same LinearLayout. (img1.pdf in attachment). when i will click the "arrow" button in the right side of the screen, it will move to the next page (img2.pdf in attachment). In teh 2nd screen, when i will click the checkbox and after that when i will click on "Done" button, it will come back to the 1st screen.
Here on this screen, the Image color will be changed as i selected the checkbox and also with thatit will display with Implants that "one " or "two" items are selected. (The Implants will be like this : "Implants(1/2)", if one check box selected."Implants(2/2)", if two checkboxes are selected).
and for the color change, i kept two ImageButton with different colors. So by selecting the checkbox, the Image color will be changed.

Please can anybody give a little suggestion how to do that?
Hope a reply.

Thanks in advance.
Attachments
img2.pdf
(27.75 KiB) Downloaded 107 times
Img1.pdf
(25.35 KiB) Downloaded 85 times
dkkundudolan
Experienced Developer
Experienced Developer
 
Posts: 83
Joined: Mon Mar 03, 2008 12:50 pm

Postby Danuubz » Wed Nov 26, 2008 11:33 am

Do you start the second screen with startActivityForResult(...) ?

Instead of two ImageButtons, I would take one single ImageButton (or simply ImageView) and call 'setImageBitmap(image1_or_2)'.
User avatar
Danuubz
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Wed Dec 19, 2007 10:44 pm
Location: Germany

Top

Postby dkkundudolan » Thu Nov 27, 2008 6:14 am

Hi Danuubz,

I tried in this way also what you said. But i cant make color change of the image. And with that there is displaying of Text in the 1st page that "Implants(1/2)", if one checkBox has selected and "Implants(2/2)", if two check boxes are selected.
what to do in this case? please, can you give a little example?

Thanks.
dkkundudolan
Experienced Developer
Experienced Developer
 
Posts: 83
Joined: Mon Mar 03, 2008 12:50 pm

Postby Danuubz » Thu Nov 27, 2008 10:30 am

I hope this helps:

(you can take two different 50x50 images 'imga.png' and 'imgb.png')

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package de.Example;
  3.  
  4.  
  5.  
  6. import android.net.*;
  7.  
  8. import android.os.Bundle;
  9.  
  10. import android.view.*;
  11.  
  12. import android.view.ViewGroup.LayoutParams;
  13.  
  14. import android.widget.*;
  15.  
  16. import android.app.*;
  17.  
  18. import android.content.*;
  19.  
  20. import android.graphics.*;
  21.  
  22. import android.graphics.drawable.*;
  23.  
  24. import android.content.res.*;
  25.  
  26.  
  27.  
  28. public class Example extends Activity
  29.  
  30. {
  31.  
  32.         public static final String SELECTED = "SELECTED";
  33.  
  34.         public static final String NOT_SELECTED = "NOT SELECTED";
  35.  
  36.        
  37.  
  38.         public static final int SETTINGS_BUTTON = 0;
  39.  
  40.        
  41.  
  42.         public static final int SETTINGS_REQUEST = 0;
  43.  
  44.        
  45.  
  46.         private Resources res;
  47.  
  48.         private Bitmap bmpA;
  49.  
  50.         private Bitmap bmpB;
  51.  
  52.        
  53.  
  54.         private ButtonListener buttonListener;
  55.  
  56.        
  57.  
  58.         private LinearLayout main;
  59.  
  60.         private LinearLayout one;
  61.  
  62.         private LinearLayout two;
  63.  
  64.         private LinearLayout three;
  65.  
  66.        
  67.  
  68.         private ImageView imgView;
  69.  
  70.         private View empty;
  71.  
  72.         private TextView tv;
  73.  
  74.        
  75.  
  76.         private CheckBox checkOne;
  77.  
  78.         private CheckBox checkTwo;
  79.  
  80.         private View emptyTwo;
  81.  
  82.        
  83.  
  84.         private Button settingsButton;
  85.  
  86.        
  87.  
  88.     @Override
  89.  
  90.     public void onCreate(Bundle savedInstanceState)
  91.  
  92.     {
  93.  
  94.         super.onCreate(savedInstanceState);
  95.  
  96.         getBitmaps();
  97.  
  98.         makeGUI();
  99.  
  100.     }
  101.  
  102.    
  103.  
  104.     private void makeGUI()
  105.  
  106.     {
  107.  
  108.         main = new LinearLayout(this);
  109.  
  110.         main.setLayoutParams(new LinearLayout.LayoutParams(320,480));
  111.  
  112.         main.setBackgroundColor(Color.WHITE);
  113.  
  114.         main.setOrientation(LinearLayout.VERTICAL);
  115.  
  116.         main.setGravity(Gravity.CENTER_HORIZONTAL);
  117.  
  118.        
  119.  
  120.         buttonListener = new ButtonListener();
  121.  
  122.        
  123.  
  124.         //
  125.  
  126.         one = new LinearLayout(this);
  127.  
  128.         one.setLayoutParams(new LinearLayout.LayoutParams(260,80));
  129.  
  130.         one.setOrientation(LinearLayout.HORIZONTAL);
  131.  
  132.         one.setGravity(Gravity.CENTER);
  133.  
  134.        
  135.  
  136.         imgView = new ImageView(this);
  137.  
  138.         imgView.setImageBitmap(bmpA);
  139.  
  140.         imgView.setLayoutParams(new LinearLayout.LayoutParams(50,50));
  141.  
  142.         one.addView(imgView);
  143.  
  144.        
  145.  
  146.         empty = new View(this);
  147.  
  148.         empty.setLayoutParams(new LinearLayout.LayoutParams(10,50));
  149.  
  150.         one.addView(empty);
  151.  
  152.        
  153.  
  154.         tv = new TextView(this);
  155.  
  156.         tv.setLayoutParams(new LinearLayout.LayoutParams(200,50));
  157.  
  158.         tv.setBackgroundColor(Color.GRAY);
  159.  
  160.         tv.setTextColor(Color.BLACK);
  161.  
  162.         tv.setText(SELECTED);
  163.  
  164.         tv.setGravity(Gravity.CENTER);
  165.  
  166.         one.addView(tv);
  167.  
  168.        
  169.  
  170.         main.addView(one);
  171.  
  172.         //
  173.  
  174.        
  175.  
  176.         //
  177.  
  178.         two = new LinearLayout(this);
  179.  
  180.         two.setLayoutParams(new LinearLayout.LayoutParams(260,80));
  181.  
  182.         two.setOrientation(LinearLayout.HORIZONTAL);
  183.  
  184.         two.setGravity(Gravity.CENTER_HORIZONTAL);
  185.  
  186.        
  187.  
  188.         checkOne = new CheckBox(this);
  189.  
  190.         checkOne.setLayoutParams(new LinearLayout.LayoutParams(50,50));
  191.  
  192.         two.addView(checkOne);
  193.  
  194.        
  195.  
  196.         emptyTwo = new View(this);
  197.  
  198.         emptyTwo.setLayoutParams(new LinearLayout.LayoutParams(10,50));
  199.  
  200.         two.addView(emptyTwo);
  201.  
  202.        
  203.  
  204.         checkTwo = new CheckBox(this);
  205.  
  206.         checkTwo.setLayoutParams(new LinearLayout.LayoutParams(50,50));
  207.  
  208.         two.addView(checkTwo);
  209.  
  210.        
  211.  
  212.         main.addView(two);
  213.  
  214.         //
  215.  
  216.        
  217.  
  218.         //
  219.  
  220.         three = new LinearLayout(this);
  221.  
  222.         three.setLayoutParams(new LinearLayout.LayoutParams(260,100));
  223.  
  224.         three.setOrientation(LinearLayout.HORIZONTAL);
  225.  
  226.         three.setGravity(Gravity.CENTER);
  227.  
  228.        
  229.  
  230.         settingsButton = new Button(this);
  231.  
  232.         settingsButton.setLayoutParams(new LinearLayout.LayoutParams(140,60));
  233.  
  234.         settingsButton.setOnClickListener(buttonListener);
  235.  
  236.         settingsButton.setId(SETTINGS_BUTTON);
  237.  
  238.         settingsButton.setText("Settings");
  239.  
  240.        
  241.  
  242.         three.addView(settingsButton);
  243.  
  244.        
  245.  
  246.         main.addView(three);
  247.  
  248.         //     
  249.  
  250.        
  251.  
  252.         setContentView(main);
  253.  
  254.     }
  255.  
  256.    
  257.  
  258.     private void getBitmaps()
  259.  
  260.     {
  261.  
  262.         res = getResources();  
  263.  
  264.         bmpA = BitmapFactory.decodeResource(res, R.drawable.imga);      
  265.  
  266.         bmpB = BitmapFactory.decodeResource(res, R.drawable.imgb);  
  267.  
  268.     }
  269.  
  270.    
  271.  
  272.     @Override
  273.  
  274.     protected void onActivityResult(int requestCode, int resultCode, Intent data)
  275.  
  276.     {          
  277.  
  278.         String result = data.getStringExtra("settings");
  279.  
  280.        
  281.  
  282.         if(requestCode == SETTINGS_REQUEST)
  283.  
  284.         {              
  285.  
  286.                 if(result.equals(SELECTED))
  287.  
  288.                 {
  289.  
  290.                         tv.setText(SELECTED);
  291.  
  292.                         checkOne.performClick();
  293.  
  294.                         checkTwo.performClick();
  295.  
  296.                         imgView.setImageBitmap(bmpB);
  297.  
  298.                         main.invalidate();
  299.  
  300.                 }
  301.  
  302.                 else
  303.  
  304.                 {
  305.  
  306.                         tv.setText(NOT_SELECTED);
  307.  
  308.                         checkOne.performClick();
  309.  
  310.                         checkTwo.setSelected(false);
  311.  
  312.                         imgView.setImageBitmap(bmpA);
  313.  
  314.                         main.invalidate();
  315.  
  316.                 }
  317.  
  318.         }
  319.  
  320.     }
  321.  
  322.    
  323.  
  324.     public class ButtonListener implements View.OnClickListener
  325.  
  326.     {
  327.  
  328.         @Override
  329.  
  330.         public void onClick(View v)
  331.  
  332.         {
  333.  
  334.                 switch(v.getId())
  335.  
  336.                 {    
  337.  
  338.                 case SETTINGS_BUTTON:
  339.  
  340.                         Intent intent = new Intent(Intent.ACTION_VIEW);
  341.  
  342.                                 intent.setClass(Example.this, SettingsActivity.class);
  343.  
  344.                                 Example.this.startActivityForResult(intent, SETTINGS_REQUEST);
  345.  
  346.                         break;
  347.  
  348.                
  349.  
  350.                 default: break;
  351.  
  352.                 }
  353.  
  354.         }
  355.  
  356.     }
  357.  
  358. }
Parsed in 0.054 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package de.Example;
  3.  
  4.  
  5.  
  6. import android.net.*;
  7.  
  8. import android.os.Bundle;
  9.  
  10. import android.view.*;
  11.  
  12. import android.view.ViewGroup.LayoutParams;
  13.  
  14. import android.widget.*;
  15.  
  16. import android.app.*;
  17.  
  18. import android.content.*;
  19.  
  20. import android.graphics.*;
  21.  
  22. import android.graphics.drawable.*;
  23.  
  24. import android.content.res.*;
  25.  
  26.  
  27.  
  28. public class SettingsActivity extends Activity
  29.  
  30. {
  31.  
  32.         public static final int SETTINGS_ACTIVITY_RESULT = 0;
  33.  
  34.        
  35.  
  36.         public static final int SELECTED = 0;
  37.  
  38.         public static final int NOT_SELECTED = 1;
  39.  
  40.        
  41.  
  42.         private LinearLayout main;
  43.  
  44.        
  45.  
  46.         private Button selectedButton;
  47.  
  48.         private Button notSelectedButton;
  49.  
  50.        
  51.  
  52.         private ButtonListener buttonListener;
  53.  
  54.        
  55.  
  56.         private Intent mIntent;
  57.  
  58.         private Intent replyIntent;
  59.  
  60.        
  61.  
  62.         @Override
  63.  
  64.     public void onCreate(Bundle savedInstanceState)
  65.  
  66.     {
  67.  
  68.         super.onCreate(savedInstanceState);
  69.  
  70.         initIntent();
  71.  
  72.         makeGUI();
  73.  
  74.     }
  75.  
  76.        
  77.  
  78.         private void initIntent()
  79.  
  80.         {
  81.  
  82.                 mIntent = this.getIntent();
  83.  
  84.                 replyIntent = new Intent();
  85.  
  86.         }
  87.  
  88.        
  89.  
  90.         private void makeGUI()
  91.  
  92.          {
  93.  
  94.             main = new LinearLayout(this);
  95.  
  96.             main.setLayoutParams(new LinearLayout.LayoutParams(320,480));
  97.  
  98.             main.setBackgroundColor(Color.WHITE);
  99.  
  100.             main.setOrientation(LinearLayout.VERTICAL);
  101.  
  102.             main.setGravity(Gravity.CENTER);
  103.  
  104.            
  105.  
  106.             buttonListener = new ButtonListener();
  107.  
  108.            
  109.  
  110.             selectedButton = new Button(this);
  111.  
  112.             selectedButton.setLayoutParams(new LinearLayout.LayoutParams(140,60));
  113.  
  114.             selectedButton.setId(SELECTED);
  115.  
  116.             selectedButton.setOnClickListener(buttonListener);
  117.  
  118.             selectedButton.setText("Selected");
  119.  
  120.             main.addView(selectedButton);
  121.  
  122.            
  123.  
  124.             notSelectedButton = new Button(this);
  125.  
  126.             notSelectedButton.setLayoutParams(new LinearLayout.LayoutParams(140,60));
  127.  
  128.             notSelectedButton.setId(NOT_SELECTED);
  129.  
  130.             notSelectedButton.setOnClickListener(buttonListener);
  131.  
  132.             notSelectedButton.setText("Not Selected");
  133.  
  134.             main.addView(notSelectedButton);
  135.  
  136.            
  137.  
  138.             setContentView(main);
  139.  
  140.          }
  141.  
  142.          
  143.  
  144.          public class ButtonListener implements View.OnClickListener
  145.  
  146.         {
  147.  
  148.                 @Override
  149.  
  150.                 public void onClick(View v)
  151.  
  152.                 {
  153.  
  154.                         switch(v.getId())
  155.  
  156.                         {    
  157.  
  158.                         case SELECTED:
  159.  
  160.                                 replyIntent.putExtra("settings", "SELECTED");
  161.  
  162.                                 setResult(SETTINGS_ACTIVITY_RESULT,replyIntent);
  163.  
  164.                                 finish();
  165.  
  166.                                 break;
  167.  
  168.                        
  169.  
  170.                         case NOT_SELECTED:
  171.  
  172.                                 replyIntent.putExtra("settings", "NOT_SELECTED");
  173.  
  174.                                 setResult(SETTINGS_ACTIVITY_RESULT,replyIntent);
  175.  
  176.                                 finish();
  177.  
  178.                                 break;  
  179.  
  180.                        
  181.  
  182.                         default: break;
  183.  
  184.                         }
  185.  
  186.                 }
  187.  
  188.           }
  189.  
  190. }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <resources>
  5.  
  6.     <string name="hello">Hello World, Example</string>
  7.  
  8.     <string name="app_name">Example</string>
  9.  
  10.     <string name="app_settings">SettingsActivity</string>
  11.  
  12. </resources>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="de.Example"
  7.  
  8.      android:versionCode="1"
  9.  
  10.      android:versionName="1.0.0">
  11.  
  12.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  13.  
  14.         <activity android:name=".Example"
  15.  
  16.                  android:label="@string/app_name">
  17.  
  18.             <intent-filter>
  19.  
  20.                 <action android:name="android.intent.action.MAIN" />
  21.  
  22.                 <category android:name="android.intent.category.LAUNCHER" />
  23.  
  24.             </intent-filter>
  25.  
  26.         </activity>
  27.  
  28.         <activity android:name=".SettingsActivity"
  29.  
  30.                  android:label="@string/app_settings">
  31.  
  32.             <intent-filter>
  33.  
  34.                 <action android:name="android.intent.action.VIEW" />
  35.  
  36.             </intent-filter>
  37.  
  38.         </activity>
  39.  
  40.  
  41.  
  42.     </application>
  43.  
  44. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
User avatar
Danuubz
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Wed Dec 19, 2007 10:44 pm
Location: Germany

Postby Tanuja » Thu Nov 27, 2008 11:27 am

Thanks alot Danuubz.........
i am trying out the same code which u have given ........
Tanuja
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Oct 30, 2008 7:13 am

Postby Tanuja » Thu Nov 27, 2008 1:18 pm

I got the outPut danuubz.........
thanx for that........
just can u help to enlarge part of the image........
just a little help..... how to do it... the outline atleast please.........

Thanks and regards
Tanuja
Tanuja
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Oct 30, 2008 7:13 am

Postby MrSnowflake » Thu Nov 27, 2008 1:58 pm

[mod]I just saw it but this is _NOT_ a tutorial -> MOVED!
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Danuubz » Thu Nov 27, 2008 4:13 pm

Tanuja wrote:I got the outPut danuubz.........
thanx for that........
just can u help to enlarge part of the image........
just a little help..... how to do it... the outline atleast please.........

Thanks and regards
Tanuja


It is less difficult than I thougt... Take an 80x80 image, where the left 40 pixels has different color from the right side.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package de.imageresizing;
  3.  
  4.  
  5.  
  6. import android.os.Bundle;
  7.  
  8. import android.view.*;
  9.  
  10. import android.view.GestureDetector.OnGestureListener;
  11.  
  12. import android.widget.*;
  13.  
  14. import android.app.*;
  15.  
  16. import android.content.*;
  17.  
  18. import android.graphics.*;
  19.  
  20. import android.content.res.*;
  21.  
  22.  
  23.  
  24. public class ImageResizing extends Activity
  25.  
  26. {    
  27.  
  28.         private Resources res;
  29.  
  30.         private Bitmap fullBitmap;
  31.  
  32.         private Bitmap partialBitmap;
  33.  
  34.        
  35.  
  36.         private Matrix m;
  37.  
  38.        
  39.  
  40.         private LinearLayout main;
  41.  
  42.         private MyImageView imgView;
  43.  
  44.        
  45.  
  46.     @Override
  47.  
  48.     public void onCreate(Bundle savedInstanceState)
  49.  
  50.     {
  51.  
  52.         super.onCreate(savedInstanceState);
  53.  
  54.         getBitmap();
  55.  
  56.         makeGUI();
  57.  
  58.     }
  59.  
  60.    
  61.  
  62.     private void makeGUI()
  63.  
  64.     {
  65.  
  66.         main = new LinearLayout(this);
  67.  
  68.         main.setLayoutParams(new LinearLayout.LayoutParams(320,480));
  69.  
  70.         main.setBackgroundColor(Color.WHITE);
  71.  
  72.         main.setOrientation(LinearLayout.VERTICAL);
  73.  
  74.                 main.setGravity(Gravity.CENTER_HORIZONTAL);
  75.  
  76.                
  77.  
  78.                 imgView = new MyImageView(this);
  79.  
  80.             imgView.setLayoutParams(new AbsoluteLayout.LayoutParams(80,80,50,50));
  81.  
  82.             imgView.setImageBitmap(fullBitmap);
  83.  
  84.              
  85.  
  86.             main.addView(imgView);
  87.  
  88.                
  89.  
  90.                 setContentView(main);
  91.  
  92.     }
  93.  
  94.    
  95.  
  96.     private void getBitmap()
  97.  
  98.     {
  99.  
  100.         res = getResources();
  101.  
  102.         fullBitmap = BitmapFactory.decodeResource(res, R.drawable.pic);  
  103.  
  104.         m = new Matrix();
  105.  
  106.     }
  107.  
  108.    
  109.  
  110.     class MyImageView extends ImageView implements OnGestureListener
  111.  
  112.     {
  113.  
  114.         private boolean isOn = false;
  115.  
  116.        
  117.  
  118.      
  119.  
  120.         private GestureDetector gesture;
  121.  
  122.      
  123.  
  124.         public MyImageView(Context context)
  125.  
  126.         {
  127.  
  128.         super(context);
  129.  
  130.           gesture = new GestureDetector(this);
  131.  
  132.         }
  133.  
  134.      
  135.  
  136.         @Override
  137.  
  138.          public boolean onTouchEvent(MotionEvent me)
  139.  
  140.          {
  141.  
  142.           gesture.onTouchEvent(me);
  143.  
  144.          
  145.  
  146.           return true;
  147.  
  148.          }    
  149.  
  150.      
  151.  
  152.         @Override
  153.  
  154.          public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
  155.  
  156.          {
  157.  
  158.           return true;
  159.  
  160.          }
  161.  
  162.          
  163.  
  164.          @Override
  165.  
  166.          public boolean onDown(MotionEvent e)
  167.  
  168.          {
  169.  
  170.           return true;
  171.  
  172.          }
  173.  
  174.          
  175.  
  176.          @Override
  177.  
  178.          public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
  179.  
  180.          {          
  181.  
  182.           return true;
  183.  
  184.          }
  185.  
  186.          
  187.  
  188.          @Override
  189.  
  190.          public void onLongPress(MotionEvent e)
  191.  
  192.          {  
  193.  
  194.          
  195.  
  196.          }
  197.  
  198.          
  199.  
  200.          @Override
  201.  
  202.          public void onShowPress(MotionEvent e) {   }    
  203.  
  204.          
  205.  
  206.          @Override
  207.  
  208.          public boolean onSingleTapUp(MotionEvent e)    
  209.  
  210.          {    
  211.  
  212.                  if(!isOn)
  213.  
  214.                  {
  215.  
  216.                          if(e.getX() < 40)
  217.  
  218.                          {
  219.  
  220.                                 m.setScale(2, 1);
  221.  
  222.                                 partialBitmap = Bitmap.createBitmap(fullBitmap,0,0,40,80,m,false);
  223.  
  224.                                 imgView.setImageBitmap(partialBitmap);  
  225.  
  226.                                 main.invalidate();
  227.  
  228.                          }
  229.  
  230.                          else if(e.getX() >= 40)
  231.  
  232.                          {
  233.  
  234.                                  m.setScale(2, 1);
  235.  
  236.                                  partialBitmap = Bitmap.createBitmap(fullBitmap,40,0,40,80,m,false);
  237.  
  238.                                  imgView.setImageBitmap(partialBitmap);
  239.  
  240.                                  main.invalidate();
  241.  
  242.                          }
  243.  
  244.                          
  245.  
  246.                          isOn = true;
  247.  
  248.                  }
  249.  
  250.                  else
  251.  
  252.                  {
  253.  
  254.                          imgView.setImageBitmap(fullBitmap);
  255.  
  256.                          isOn = false;
  257.  
  258.                  }
  259.  
  260.          
  261.  
  262.                  return true;
  263.  
  264.          }          
  265.  
  266.     }
  267.  
  268. }
  269.  
  270.  
Parsed in 0.049 seconds, using GeSHi 1.0.8.4
User avatar
Danuubz
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Wed Dec 19, 2007 10:44 pm
Location: Germany

Postby Tanuja » Fri Nov 28, 2008 6:58 am

Hi.........
i m not getting the result....... where i click the mouse that part is not maximizing.....
please help...... its urgent....

thanks
Tanuja
Tanuja
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Oct 30, 2008 7:13 am

Postby dkkundudolan » Fri Nov 28, 2008 7:12 am

Hi Danuubz ,

Thank you very much for your quick reply. Its working nicely.

But , here i want the two checkboxes in the "SettingsActivity" pages. not in the "Example" page.
And in the "SettingsActivity" page, there will be one button. By clicking that particular button , it will display the text as "Selected" or deSelected". Means how many checkBox will be selected, it depends in that.
This my actual problem,
Remaining all will be same.
please can you help a little......

Thanks again.
dkkundudolan
Experienced Developer
Experienced Developer
 
Posts: 83
Joined: Mon Mar 03, 2008 12:50 pm

Postby Tanuja » Fri Nov 28, 2008 9:44 am

Hi Danuubz.........
i got the output for that maximizing and minimizing.... now the second cod eit does only single part of the image to enlage on mouse click........... and if the click is made on more than 40 ........ a potion of it enlarge
......... but what i want is .... wherever i click the mouse...... that part shuold increase till were i pull the mouse.......
any help on this ..... please
thanks and regards
Tanuja
Tanuja
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Oct 30, 2008 7:13 am

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 26 guests