fix scaling

This commit is contained in:
mmarc471@gmail.com
2020-09-06 14:16:45 +02:00
parent d095a3418f
commit 589d6b7a80
2 changed files with 17 additions and 6 deletions
@@ -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 { 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); this(x_pos,y_pos,name);
float x_scaled_size = x_size*bitmap.getWidth()/100; float x_scaled_size = x_size*MainActivity.screenWidth/100;
float y_scaled_size = y_size*bitmap.getHeight()/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) if(x_scaled_size <=0 || y_scaled_size <=0)
{ {
throw new InvalidDataException(name,x_scaled_size,y_scaled_size); 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; this.bitmap=scaledBitmap;
} }
@@ -23,6 +23,7 @@ public class MainActivity extends Activity {
public static int screenWidth=0; public static int screenWidth=0;
public static int screenHeight=0; public static int screenHeight=0;
public static boolean bilinearFiltering = true;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -37,13 +38,20 @@ public class MainActivity extends Activity {
//return portrait mode resolution so we need to flip them //return portrait mode resolution so we need to flip them
Point size = new Point(); Point size = new Point();
display.getSize(size); display.getSize(size);
if(size.y > size.x)
{
screenWidth = size.y; screenWidth = size.y;
screenHeight = size.x; screenHeight = size.x;
}else{
screenWidth = size.x;
screenHeight = size.y;
}
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.debug_card); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.debug_card);
try { 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)); v.addToDraw(new Drawable(bm,0.0F,00.0F,"Card1",50F,50F));
} catch (InvalidDataException e) { } catch (InvalidDataException e) {
//cette erreur est lance si un carre est invalid //cette erreur est lance si un carre est invalid