fix scaling
This commit is contained in:
@@ -55,15 +55,18 @@ public class Drawable {
|
||||
public Drawable(Bitmap bitmap,float x_pos,float y_pos,String name,float x_size,float y_size) throws InvalidDataException {
|
||||
this(x_pos,y_pos,name);
|
||||
|
||||
float x_scaled_size = x_size*bitmap.getWidth()/100;
|
||||
float y_scaled_size = y_size*bitmap.getHeight()/100;
|
||||
float x_scaled_size = x_size*MainActivity.screenWidth/100;
|
||||
float y_scaled_size = y_size*MainActivity.screenHeight/100;
|
||||
|
||||
System.out.println(x_scaled_size + " y: " + y_scaled_size);
|
||||
System.out.println(y_size);
|
||||
|
||||
if(x_scaled_size <=0 || y_scaled_size <=0)
|
||||
{
|
||||
throw new InvalidDataException(name,x_scaled_size,y_scaled_size);
|
||||
}
|
||||
|
||||
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size,true);
|
||||
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size,MainActivity.bilinearFiltering);
|
||||
this.bitmap=scaledBitmap;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ public class MainActivity extends Activity {
|
||||
|
||||
public static int screenWidth=0;
|
||||
public static int screenHeight=0;
|
||||
public static boolean bilinearFiltering = true;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -37,13 +38,20 @@ public class MainActivity extends Activity {
|
||||
//return portrait mode resolution so we need to flip them
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
screenWidth = size.y;
|
||||
screenHeight = size.x;
|
||||
if(size.y > size.x)
|
||||
{
|
||||
screenWidth = size.y;
|
||||
screenHeight = size.x;
|
||||
}else{
|
||||
screenWidth = size.x;
|
||||
screenHeight = size.y;
|
||||
}
|
||||
|
||||
|
||||
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.debug_card);
|
||||
|
||||
try {
|
||||
//v.addToDraw(new Drawable(new Rect(0,0,screenHeight,screenWidth),"background",Color.BLUE));
|
||||
v.addToDraw(new Drawable(new Rect(0,0,screenWidth,screenHeight),"background",Color.BLUE));
|
||||
v.addToDraw(new Drawable(bm,0.0F,00.0F,"Card1",50F,50F));
|
||||
} catch (InvalidDataException e) {
|
||||
//cette erreur est lance si un carre est invalid
|
||||
|
||||
Reference in New Issue
Block a user