Change resolutions of java

How to Change Screen Resolution Programmatically?

Let me tell you my problem. I want to change my screen resolution. I can change it in an application but it changes only application’s screen. I wanna set system’s resolution so it won’t be important which application is running on front. My device’s resolution is set as 1280 * 720 p. Can I make it 1260 * 680? If it requires to make changes in Android source code, I can. Just tell me where to change. Waiting for your help.

I’ve come across LCD Density, an app that does precisely that. Seeing if I can find out how it does it.

How can you change resolution from java code ? I have device (android 4.4) that is connected to HDMI screen and I can use system settings > display > resolution > DACOUT_1080P_60 and monitor switches to 1080p but my application is always rendering to 720p even when I set resolution 480p

3 Answers 3

This thread on xda-developers should set you on the right track.

@user511853 Changing real pixels would require ripping out the screen and putting a new one in. Changing pixel density is what you want, promise!

Searching too a valid answer to this, but I have a lead to the solution : WARNING Experimental buggy stuff :

/* Requires android.permission.WRITE_SETTINGS and android.permission.WRITE_SECURE_SETTINGS, thus it requires the app to be a system app. */ public void changeResolution(int x, int y) < try < Class c = Class.forName("android.os.ServiceManager"); try < Method method = c.getDeclaredMethod("checkService", String.class); try < IWindowManager mWindowManager = IWindowManager.Stub.asInterface((IBinder) method.invoke(null,Context.WINDOW_SERVICE)); try < mWindowManager.setForcedDisplaySize(Display.DEFAULT_DISPLAY,x,y); >catch (RemoteException e) > catch (IllegalAccessException e) catch (InvocationTargetException e) > catch (NoSuchMethodException e) > catch (ClassNotFoundException e) > 

Add a reduced AIDL version of IWindowManager to your project : /app/src/main/aidl/android/view/IWindowManager.aidl

package android.view; interface IWindowManager < boolean startViewServer(int port); // Transaction #1 boolean stopViewServer(); // Transaction #2 boolean isViewServerRunning(); // Transaction #3 void setForcedDisplaySize(int displayId, int width, int height); void clearForcedDisplaySize(int displayId); void setForcedDisplayDensity(int displayId, int density); void clearForcedDisplayDensity(int displayId); >

The app will require to be in the system apps folder. It does something for sure, but right now it also lead to severe bugs. Rebooting seems to cancel changes.

Читайте также:  Javascript declare variable if not declared

Waiting for feedback on this.

Источник

Change screen resolution in Java

I have a program that uses visual scripting (sikuli-script) to allow the users to create their own visual scripts. The program needs to work across multiple systems that could have different screen resolutions. Sikuli matches highlighted images on a pixel-by-pixel basis, so on systems with different resolutions will fail to find images. Therefore is there a way that I can change the resolution settings in windows through java code? Going full-screen is not an option as images that need to be captured come from different software packages, i.e. my software package sits above where the images need to come from (and is minimized when a capture is taking place)

1 Answer 1

Therefore is there a way that I can change the resolution settings in windows through java code?

import java.awt.Color; import java.awt.DisplayMode; import java.awt.Frame; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import java.awt.image.BufferStrategy; public class MultiBufferTest < private Frame mainFrame; private static Color[] COLORS = new Color[]< Color.red, Color.blue, Color.green, Color.white, Color.black, Color.yellow, Color.gray, Color.cyan, Color.pink, Color.lightGray, Color.magenta, Color.orange, Color.darkGray>; private static DisplayMode[] BEST_DISPLAY_MODES = new DisplayMode[]< new DisplayMode(640, 480, 32, 0), new DisplayMode(640, 480, 16, 0), new DisplayMode(640, 480, 8, 0)>; public MultiBufferTest(int numBuffers, GraphicsDevice device) < try < GraphicsConfiguration gc = device.getDefaultConfiguration(); mainFrame = new Frame(gc); mainFrame.setUndecorated(true); mainFrame.setIgnoreRepaint(true); device.setFullScreenWindow(mainFrame); if (device.isDisplayChangeSupported()) < chooseBestDisplayMode(device); >Rectangle bounds = mainFrame.getBounds(); mainFrame.createBufferStrategy(numBuffers); BufferStrategy bufferStrategy = mainFrame.getBufferStrategy(); for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) < for (int i = 0; i < numBuffers; i++) < Graphics g = bufferStrategy.getDrawGraphics(); if (!bufferStrategy.contentsLost()) < g.setColor(COLORS[i]); g.fillRect(0, 0, bounds.width, bounds.height); bufferStrategy.show(); g.dispose(); >try < Thread.sleep((int) lag); >catch (InterruptedException e) < >> > > catch (Exception e) < e.printStackTrace(); >finally < device.setFullScreenWindow(null); >> private static DisplayMode getBestDisplayMode(GraphicsDevice device) < for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) < DisplayMode[] modes = device.getDisplayModes(); for (int i = 0; i < modes.length; i++) < if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth() && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight() && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth()) < return BEST_DISPLAY_MODES[x]; >> > return null; > public static void chooseBestDisplayMode(GraphicsDevice device) < DisplayMode best = getBestDisplayMode(device); if (best != null) < device.setDisplayMode(best); >> public static void main(String[] args) < try < int numBuffers = 2; if (args != null && args.length >0) < numBuffers = Integer.parseInt(args[0]); if (numBuffers < 2 || numBuffers >COLORS.length) < System.err.println("Must specify between 2 and " + COLORS.length + " buffers"); System.exit(1); >> GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); MultiBufferTest test = new MultiBufferTest(numBuffers, device); > catch (Exception e) < e.printStackTrace(); >System.exit(0); > > 

2.don’t do that, could annoying users, and on code lack can to change resolution in Native OS (my coworker has more than 100shortcuts on three screen, any change for resolution to change shotcuts size and location , result is simple mess)

3.use JLabel for Icons (layed with proper LayoutManager into container), or put Icons to the JList or JTable , then you never / don’t care about something

4.use only LayoutManager rather than possitioning or change for screen resolution, you can set for smaller Size (for JFrame ) on the screen for Apps start_up , let’s user decide about final Dimmension on her/his screen

Источник

(Java) Graphics change resolution?

I currently have this running undecorated in a JFrame , 1920x1080p as per the resolution of my laptop. I’m curious as to whether there is any way to alter the resolution of the Graphics rendered, particularly lowering resolution so as to increase efficiency/speed, or fitting to another differently sized screen. There are many objects being rendered with a camera and the game runs fairly well, but any usable alterations to the resolution would be useful as optional in my settings. I’ve researched this and found no good answers. Thank you for your time.

1 Answer 1

(Resolution changes such as for printing.)

Best to use a drawImage with a smaller image, and scaled width and height.

Now, you could even render all in your own BufferedImage using a Graphics2D with BufferedImage.createGraphics and scale afterwards. Not so nice for text or printing.

Or use Graphics2D scaling:

g.scale(2.0, 2.0); . // Draw smaller image g.scale(0.5, 0.5); 

As you might imagine this probably does not help in memory consumption, apart from needing smaller images. At one point all pixels of the image must be given in the devices color size. 256 colors gif, or 10KB jpg will not help.

The other way around, supporting high resolutions with tight memory also exists. There one might use tiled images, see ImageIO .

Important is to prepare the image outside the paintComponent / paint .

You might also go for device compatible bit maps if you make your own BufferedImage, but this seems circumstantial (GraphicsEnvironment).

Источник

How to set resolution of a Java app/the system resolution in fullscreen exclusive mode?

There are three complex example you may interested in oracle tutorials.

Do you want to use high-performance graphics in the Java development environment? Have you always wanted to program a game, but your images wouldn’t move fast enough? Has your slide show program not worked properly because you had no control over the user’s display resolution? If you’ve been asking any of these questions, then the full-screen exclusive mode API, introduced in release 1.4, may be what you’re looking for.

CapabilitiesTest demonstrates the different buffering capabilities available for the machine on which it is run.

DisplayModeTest shows a Swing application that uses passive rendering. If full-screen exclusive mode is available, it will enter full-screen exclusive mode. If display mode changes are allowed, it allows you to switch between display modes.

MultiBufferTest enters full-screen mode and uses multi-buffering through an active render loop.

EDIT:

Here is a sample app does what you want:

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DisplayModeChanger extends JFrame < private GraphicsDevice device; private static JButton changeDM = new JButton("800X600 @ 32 BIT 60HZ"); private boolean isFullScreenSupported = false; public DisplayModeChanger(final GraphicsDevice device) < this.device = device; setDefaultCloseOperation(EXIT_ON_CLOSE); changeDM.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < DisplayMode dm = new DisplayMode(800, 600, 32, 60); device.setDisplayMode(dm); setSize(new Dimension(dm.getWidth(), dm.getHeight())); validate(); >>); > public void goFullScreen() < isFullScreenSupported = device.isFullScreenSupported(); setUndecorated(isFullScreenSupported); setResizable(!isFullScreenSupported); if (isFullScreenSupported) < device.setFullScreenWindow(this); validate(); >else < pack(); setVisible(true); >> public static void main(String[] args) < GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = env.getDefaultScreenDevice(); DisplayModeChanger changer = new DisplayModeChanger(defaultScreen); changer.getContentPane().add(changeDM); changer.goFullScreen(); >> 

Источник

Оцените статью