I'm using a Samsung Galaxy S20 phone and I'm trying to get the width of the display using:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
height2 = metrics.heightPixels;
width2 = metrics.widthPixels;
This returns 810, but seeing the phone specifications on the internet the actual screen width is 1080. I started having problems in code because of this, is there a way to get the actual screen width in Java?
Related
I'm trying to get the real resolution of the device, here it's Samsung Galaxy S7, but it doesn't work on SGS 6 also.
I've tried using Java's DisplayMetrics:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels;
int height=dm.heightPixels;
-this returns 1920x1080.
Tried Unreal Engine's:
FPlatformMisc::GetHardwareWindow()
GEngine->GameViewport->Viewport->GetSizeXY()
-both wrong.
The desired result is 2560x1440. Any ideas?
Edit: I'm working on UE 4.10
I'm late, I know, but if someone is facing with this problem I solved with this:
Display display = activity.getWindowManager().getDefaultDisplay();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
scwidth = display.getMode().getPhysicalWidth();}
I have an image and want to scale it down using imgscalr [1].
The source image's size is 1836 x 3264 (so it's portrait mode) and destination resolution is 1336 x 768.
The failure is that the image is in landscape mode and not portrait mode anymore after scaling. The scaling itself works like a charm.
My code:
BufferedImage src = ImageIO.read(new File("sourceimage.jpg"));
BufferedImage scaled = Scalr.resize(src, Scalr.Method.SPEED, Scalr.Mode.FIT_TO_HEIGHT, 1336, 768, Scalr.OP_ANTIALIAS);
ImageIO.write(scaled, "jpg", f);
The metadata of the file looks correct (orientation = 1).
My expactation is when downscaling an portrait picture that it is still a portrait picture after the scaling process.
I also tried some other libraries/classes like this: https://frickelblog.wordpress.com/2009/06/08/fast-image-scaling-in-java/ but the effect is the same.
Can you please help me? This one drives me crazy! I'm pretty sure there is just a detail to change.
[1] http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/#maven
edit:
Here's the original image: http://i.stack.imgur.com/NEc8j.jpg
the scaled version: http://i.stack.imgur.com/SYx6p.jpg
So the problem isn't with ImgScar but with ImageIO, ImageIO won't read the orientation of the image, so it was been read in as 3264x1836 - Landscape.
So what I ended up doing was rotating the image 90 degrees...
BufferedImage src = ImageIO.read(new File("/Users/swhitehead/Downloads/original.jpg"));
System.out.println(src.getWidth() + "x" + src.getHeight());
BufferedImage rotated = Scalr.rotate(src, Scalr.Rotation.CW_90, Scalr.OP_ANTIALIAS);
BufferedImage scaled = Scalr.resize(rotated, Scalr.Method.SPEED, Scalr.Mode.FIT_TO_HEIGHT, 1336, 768, Scalr.OP_ANTIALIAS);
System.out.println(scaled.getWidth() + "x" + scaled.getHeight());
ImageIO.write(scaled, "jpg", new File("Scaled.jpg"));
Which seems to have fixed "this" problem.
You can have a look at ImageIO.read( ) always rotates my uploaded picture for more details
Browsers implement <img> differently.
Firefox will not read the EXIF-information so portrait pictures are displayed in landscape.
Chrome does read out the EXIF-information so portait stays portrait.
I fixed it with this CSS declaration:
image-orientation: from-image;
I'm developing an Android app that needs to support 2.3+. I'm using HoloEverywhere as a layout library. My app runs perfectly on smartphones and tablets, but for now I'm using the same layout for all devices, so, in tablets there is a lot of blank space in a lot of layouts. So, I thinking if is possible to show this layout as a popup (AlertDialog) just on large screens.
I searched the internet for a response but every response I look isn't applying to my case. I don't want to change my layouts files (and, of course, I don't want to create new layout files).
Can anyone give a direction to solve my problem, or the unique way is to create new layouts for large screens?
You can use your own layout file as the content view of a dialog. With a custom view you can create other/bigger dialogs for your tablets. It is also possible to create a dialog from an activity. See http://developer.android.com/guide/topics/ui/dialogs.html#ActivityAsDialog or http://developer.android.com/guide/topics/ui/dialogs.html#FullscreenDialog
You can change the theme of activity to dialog in Manifest file. See:
<activity
android:name="Activity"
android:label="Home"
android:theme="#android:style/Theme.Holo.Dialog">
</activity>
You can use this code to change the height and width of my activity in onCreate()..It provides better flexibility than specifying dialog theme
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
requestWindowFeature(Window.FEATURE_ACTION_BAR);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
android.view.WindowManager.LayoutParams params =
getWindow().getAttributes();
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
params.height = LayoutParams.WRAP_CONTENT;
params.width = (int) (width / 1.2); // fixed width
params.alpha = 1.0f;
params.dimAmount = 0.5f;
getWindow().setAttributes((android.view.WindowManager.LayoutParams)
params);
I want to resize my images (original size is 1080p) but they don't resize properly and I don't know why. The Images just don't have the right size sometimes. On my emulator and my old 800*480 smartphone it works fine but on my nexus 4 with 1280*768 things don't look right. There is no problem reading the right screen resolution. There is just a bug with my resize procedure. Please help me. Heres a Snippet:
private Bitmap bitmap,bitmap1;
private float factor;
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displaymetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(displaymetrics);
width = displaymetrics.widthPixels;
height = displaymetrics.heightPixels;
factor = (float)height/1080;
Int bitmapheight,bitmapwidth;
bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.picture),(int)(factor*BitmapFactory.decodeResource(getResources(), R.drawable.picture).getwidth() ,(int)(factor*BitmapFactory.decodeResource(getResources(), R.drawable.picture).getHeight(), true);
canvas.drawBitmap(bitmap,.....
In the end the height is not resized to 768/1080*bitmapheight on my nexus and i don't know why. Note everything else works. Mathmatics indicates that the height should be the same on every phone.
These are screenshots of my programm showing the images have not the same height
First image:
Second:
As you can see the Images are not equal in terms of height. On my emulator and my old smartphone they look right. The Images should not touch the bottom but on my nexus 4 they do touch the bottom.
For anyone who is interessted why it didnt work. Finally i found out.
Now
BitmapFactory.decodeResource(getResources(), R.drawable.picture)
not only loads the pictures but also scales it depending on your resolution ( not always just on some resolution) thats why it confused me. I thought it just loads the damn picture. Now how to solve this:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
BitmapFactory.decodeResource(getResources(), R.drawable.picture,opts)
Does somebody know if the properties displayWidth and displayHeight (in OpenDDR) are in pixels or in millimeters? I tried to find the id but I am not successful.
I found it: displayWidth and displayHeight (in OpenDDR) are in pixels
I found it:displayWidth and displayHeight (in Open DDR) are in pixels.