scaling images to size of screen

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

scaling images to size of screen

Postby dreamdelerium » Sun Feb 07, 2010 10:27 pm

hello everyone,
below is a class i created to create a "Cards" object. How do i scale the image it creates to an appropriate size for different size phones? or did i not create the class correctly? thanks for your help.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class cards {
  3.  
  4.  private Bitmap img; // the image of the ball
  5.  
  6.  private int coordX = 0; // the x coordinate at the canvas
  7.  
  8.  private int coordY = 0; // the y coordinate at the canvas
  9.  
  10.  private int sizeH = 57; // the x coordinate at the canvas
  11.  
  12.  private int sizeW = 120; // the y coordinate at the canvas
  13.  
  14.  
  15.  
  16.  private boolean isSelected = false;
  17.  
  18.  private int id;
  19.  
  20.  private String cardName;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.         public cards(Context context, int drawable) {
  27.  
  28.  
  29.  
  30.                 BitmapFactory.Options opts = new BitmapFactory.Options();
  31.  
  32.         opts.inJustDecodeBounds = true;
  33.  
  34.      
  35.  
  36.         img = BitmapFactory.decodeResource(context.getResources(), drawable);
  37.  
  38.     this.id=id;
  39.  
  40.     this.cardName=cardName;
  41.  
  42.  
  43.  
  44.         }
  45.  
  46.        
  47.  
  48.  
  49.  
  50.        
  51.  
  52.         void setX(int newValue) {
  53.  
  54.         coordX = newValue;
  55.  
  56.     }
  57.  
  58.        
  59.  
  60.         public int getX() {
  61.  
  62.                 return coordX;
  63.  
  64.         }
  65.  
  66.         public int getH() {
  67.  
  68.                 return sizeH;
  69.  
  70.         }
  71.  
  72.         public int getW() {
  73.  
  74.                 return sizeW;
  75.  
  76.         }
  77.  
  78.         void setY(int newValue) {
  79.  
  80.         coordY = newValue;
  81.  
  82.    }
  83.  
  84.        
  85.  
  86.         void setW(int newValue) {
  87.  
  88.         sizeW = newValue;
  89.  
  90.    }
  91.  
  92.        
  93.  
  94.         void setH(int newValue) {
  95.  
  96.         sizeH = newValue;
  97.  
  98.    }
  99.  
  100.        
  101.  
  102.         public int getY() {
  103.  
  104.                 return coordY;
  105.  
  106.         }
  107.  
  108.        
  109.  
  110.         void setName(String newValue) {
  111.  
  112.         cardName = newValue;
  113.  
  114.    }
  115.  
  116.        
  117.  
  118.         public String getName() {
  119.  
  120.                 return cardName;
  121.  
  122.         }
  123.  
  124.        
  125.  
  126.         void setIsSelected(boolean newValue) {
  127.  
  128.         isSelected = newValue;
  129.  
  130.    }
  131.  
  132.        
  133.  
  134.         public boolean getIsSelected() {
  135.  
  136.                 return isSelected;
  137.  
  138.         }
  139.  
  140.        
  141.  
  142.         public int getID() {
  143.  
  144.                 return id;
  145.  
  146.         }
  147.  
  148.        
  149.  
  150.         public Bitmap getBitmap() {
  151.  
  152.                 return img;
  153.  
  154.         }
  155.  
  156.  
  157.  
  158.         void setImg(Bitmap newValue) {
  159.  
  160.         img = newValue;
  161.  
  162.    }
  163.  
  164.         void setID(int newValue) {
  165.  
  166.         id = newValue;
  167.  
  168.    }   
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.        
  177.  
  178.        
  179.  
  180. }
  181.  
  182.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
dreamdelerium
Developer
Developer
 
Posts: 30
Joined: Fri Jan 01, 2010 11:19 pm

Top

never mind

Postby dreamdelerium » Mon Feb 08, 2010 3:44 am

i used this: img = Bitmap.createScaledBitmap(img,Width,Height, false);
and it seems to work
dreamdelerium
Developer
Developer
 
Posts: 30
Joined: Fri Jan 01, 2010 11:19 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests