I have worked in java i need to resize proportionally as BC resizing images using fill_proportional algorithm. When U need resizing I have gone through different option and exact solution i am getting from BC, here they resize image that fit to layout. Click here to see BC comments. The solution on the above link is perfect and I am looking for the similar solution in java. So can anybody suggest me a solution in java to create an image that fill in a particular area like the link above?
Related
I have a very, very, very simple application that I'm working on (been trying my luck at writing an app in Java instead of Unity) and I have a background image that is fullscreen, this image has a lot of design and scales well with every device, and looks great (tested on every resolution we can think of).
However the text doesn't want to stay where it belongs, and that's not permissible. We have a basic setup, similar to this (however with about 6 hours of design work put into it):
and we need text to be centered in the squares at all times. How can we do this? Do we have to manually position and size it for each resolution? That seems like hell.
With a relative layout, if I understand correctly, the boxes will be parents and the text that goes into the boxes will be the children. You can put your TextViews into the boxes and then use things like android:layout_centerVertical or android:layout_centerHorizontal in order to make sure they are centered. Make sure to use sp for your font size so that it scales correctly with the density of the display.
Currently I seek a solution to simple situation, which appeares to become tricky. I need 7 togglebuttons in android app, which are a simple black circles, but I need them to be in the row and fill parent (screen) horizontally. As a resource I use big .jpeg image of a circle. To make them fill all screens in the same mode, I put them into LinearLayout with
#android:layout_width = "fill_parent";
#android:layout_height = "wrap_content";
#android:weight="70";
Weight is 70, so each button received 10. The problem is that source image is too big, which unfortunately results in...this:
(because I dont have enough reputation for posting images, here is the link
http://postimg.org/image/f8wvs5si1/ )
Sorry for small amount of code and this picture taken via phone, I do not have an internet access on the computer with eclipse and this project for some time. I tried of course to change layout_height on other possibilites, but it didnt work. I could put a weight sum also on the vertical position, but on different screens it wouldn't look same.
I also tried to change the height programmatically in onCreate method,
buttonX.setHeight(buttonX.getWidth());
or do the same with a layout, but nothing helped
Perhaps the question is dumm, but I would be glad to hear some ideas.
This is due to screen density variations. There are several things you can do to fix this:
Use different images for each density (but I'm assuming you're looking for another solution)
Use DisplayMetrics to get the actual width of the screen and then set width/height accordingly.
This code:
buttonX.setHeight(buttonX.getWidth());
probably doesn't work because you are calling it before the layout is drawn, and therefore the width is not the drawn width. You can fix this using ViewTreeObserver like here:
How can you tell when a layout has been drawn?
Use an XML attribute like scaleType="centerFit" Personally, I find these confusing because scaleType attributes don't always seem to behave the same way to me. You might have to try different ones, but sometimes they come in handy if you need an XML only solution.
I`m currently making an application to manage other application on windows.
when i resize the icon it change quality
i`m getting icon by this code
ShellFolder shell = ShellFolder.getShellFolder(new File(load1.getString("Path")));
image = shell.getIcon(true);
And when i resize it it change the quality.
My resize code is
sIMG = image.getScaledInstance(45, 45, Image.SCALE_AREA_AVERAGING);
What i want to do to keep the quality of the icon.
Please help.
I'm assuming you want to re-size your icon to look the same no matter what size you change it to. Regular images will are composed of pixels therefore lost of quality is inevitable.
When I did a web design project at my school I learned about Vector images(.svg).
Summary Of Vector Vs Bitmap http://etc.usf.edu/techease/win/images/what-is-the-difference-between-bitmap-and-vector-images/
Of course anyone please correct me if I'm wrong but I think vectors is the only way you can achieve your goal assuming that I'm understanding your question. Vector image quality does not change much or at all on re-size.
Java doesn't natively support Vector Images but follow this tutorial and you should achieve your goal. (It's not really a tutorial more like copy and paste)
http://plindenbaum.blogspot.com/2009/07/simple-java-based-svg-renderer.html
Also this link will let you convert your existing images to SVG
http://vectormagic.com/home
(you get 2 downloads when you sign up) There are other tools to convert to SVG but this was the quickest solution I could find. If you're good with Photoshop I think I saw some tutorials for it but don't quote me on that.
I hope this is what you were looking for best of luck to.
you can resize any image by the following code.
$thumb = new Imagick();
$thumb->readImage('myimage.gif'); $thumb->resizeImage(320,240,Imagick::FILTER_LANCZOS,1);
$thumb->writeImage('mythumb.gif');
$thumb->clear();
$thumb->destroy();
For more information please go to the following link.
resize image
resize optimized image
What would be the easiest way to make plain text on a swing component have a glowing effect in the background?
Example: From ->
The difference may not be that noticeable but there's definitely a glow in the second image. Thanks in advance. And by the way I couldn't find any answers for this question in java.
The easiest way is probably to draw the text on top of a blurred version of itself. The blurred version will provide the "glow" around the edges.
You will probably need to experiment with the right amount of blur and level of transparency when drawing the blurred version to get the right effect.
For blurring techniques see: How do I blur an image?
I'm trying to develop a Java program that does the following:
uses a background picture of a network diagram of clients
positions an image of a bandwidth graph to respective client
refreshes the image of graph every 5 seconds which it fetches from another program that constantly produces snapshots of bandwidth
Now, I can set the background picture and I'm pretty confident that I will be able to refresh the images by using a timer. What I am trying to plan out is how I am going to position these images to the respective clients which is displayed in the background picture. I did some research and it appears that I have several options but I want to make sure I am choosing the right one before I run into problems further down the line.
It seems to me that using a GridBagLayout would be the choice for me, however I would like a second opinion for a more experienced population. If using a GridBagLayout is the correct choice, could you recommend any good tutorials that would help me understand this Layout Manager? Please keep in mind that I have limited experience with Java, especially with GUI oriented Java.
EDIT: If I am not explaining the concept well enough please let me know.
check this out-
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
GridLayout is likely to meet your needs and it is easy to use - the assumption I make is that image of bandwidth graph is the same/fixed ...
Look for an example here
http://www.roseindia.net/tutorialsearch/?t=java+gridlayout+color
Try Google the keyword "GridLayout" - there are plenty of hits ...
If you want to do advanced layouts, you should take a look at MigLayout.
It's an extremely flexible layout manager that can pretty much act as a replacement for any/all of the existing Swing layout managers. It's worth using if you want to do difficult / complex layouts.
It feels more like a HTML table layout tool, enabling multi-column spans etc. and arbitrary scaling rules.
The "Quick Start Guide" is very good with lots of examples - I'd suggest taking a look at that if you want to evaluate MigLayout for your project.
If the 'bandwidth graph' image(s) is on top of the BG image, look to OverlayLayout
A layout manager to arrange components over the top of each other. ..
OTOH I would not use a layout strategy for this, instead..
Create a BufferedImage the size of the BG.
Paint the BG to the image.
Display the image in a label.
When it comes time to paint the graphs, get a Graphics instance for the image in the label, and paint them to that. If the graphs are always the same size and shape and do not have transparency, you can simply paint them. Otherwise, draw the BG first.