I am working with a java swing application project. I want to make an image as icon in my JPanel but it seems to be low quality image when i am printing the image using the external printer. Here is the code
ImageIcon ii=new ImageIcon(scaleImage(90, 107, ImageIO.read(new File(f.getAbsolutePath()))));
image.setIcon(ii);
How can I make high quality image icon other than this method?
If you use a downscaled version of an image for an Icon, the resolution loss cannot be compensated when printing the icon.
Instead of using ImageIcon, you can create your own icon class (by implementing the javax.swing.Icon interface, it's actually quite simple), which keeps your Image at a higher resolution and paints it at a smaller size (but without quality loss, so you still can see more detail when printing it).
This can be done by applying an AffineTransform/Scale prior to drawing the Image, or by using graphics.drawImage(x,y,width,height,imageObserver).
Related
I am new to Android development. I know there must be a easy solution, but I'm unable to figure it out.
I am drawing an image using canvas.drawText(number, margin, 50, mPaintText). Here is how I've initialised TextPaint. mPaintText = new TextPaint() and mPaintText.setTextSize(4f). The number I am trying to draw is 1234567890.
When I see the image from gallery. It looks very tiny, which is perfect for me. But, after zooming too, it's not clear. It seems to be losing resolution. I don't want to increase font size though, because the space it occupies relative to image size is absolutely perfect to me. Any insight ? Actual Image Zoomed in Image
I'm new to LIBGDX game development, and I have faced my first problem. I've created 9.patch drawables (buttons) using texture packer. This drawables can be used on low density and also extra high density screens and quality is the same.
If I run my project with that drawable on desktop project the image shown is okay and perfect size. If I run project on low density android device, drawable becomes huge (almost half of the screen). And also If I run project on extra high density android device the button becomes really small.
So my question is, how to handle drawables in LIBGDX, so the ratio (screen:image size), stays the same no matter resolution/density..?
If your button is a text button. Change the font of your text.
If you are using image button, this might help you
It kind of depends on what you're drawing...If you are just drawing an image, I've found it easier to specify a float width and height in the last 2 parameters of the draw method. If you are using a camera with a fixed viewport size, you can simply use a fixed percentage of your camera viewport so it will always be the same dimensions and draw like this:
batch.draw(drawable,x,y,screenwidth * 0.5f,screenheight*0.5f);
However, if you are using buttons or some other widget inside of a table, you should specify the cell size and it should automatically be resized based on the size of the table cell. Something like:
myTable.add(myWidget).width(300).height(200);
Post up exactly what it is that you need to draw if you get a chance and it will be easier to figure out what needs to happen.
I am trying to upgrade a Java Swing Application, and I have a part where I manipulate some small icons I am drawing in my application as BufferedImages. I want a few specific icons at certain circumstances to display an additional triangle symbol on top. The symbol+triangle is considered after the addition as a simple symbol and I thought it would be easier to do if I could resize the BufferedImage I have already and draw on top. But I have not been able to do so. Is there any efficient way to do this?
So I have no clue why this is happening. I am using Universal Image Loader to load these images. It seems like the last line of pixels is being streched for some weird reason. I want the image to just stretch out evenly. (I don't care that it will look weird. The images below are for demo purposes.)
Also, don't mind the first and last image. I purposely blurred that out because it had someone's face on it.
This is how I set up my Universal Image Loader:
//setup Image Loader for loading cruise line logos
displayImageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)//show this image when image is loading
.showImageForEmptyUri(R.drawable.ic_launcher)//show this image incase image doesn't exist
.showImageOnFail(R.drawable.ic_launcher)//show this image if fetching image from URL didn't work
.cacheInMemory(true)//cache image in RAM
.cacheOnDisc(true)//cache image in device for later use
.considerExifParams(true)
.displayer(new RoundedBitmapDisplayer(5))//super subtle rounded corners on images
.build();
This is caused by the way RoundedBitmapDisplayer draws the bitmap.
If you look at the source, you'll see that it uses a RoundedDrawable, which uses canvas.drawRoundRect() to draw a rounded rectangle of the desired size of the Drawable, using the downloaded image as the texture via a BitmapShader. BitmapShader does not support scaling (only clamping and tile modes). Try using a SimpleBitmapDisplayer instead which uses the normal ImageView.setImageBitmap() way of displaying the image.
If you need rounded corners, you'll have to find a different way to implement that, for example by scaling the Bitmap to the desired size first. Another option is to call Canvas.saveLayer() before delegating to BitmapDrawable for the scaling, and then applying the rounded corner masking effect using PorterDuff.Mode.DST_IN. Either way you'll end up writing a bit more low-level code, but you should be able to encapsulate everything nicely in a custom BitmapDisplayer.
I'm trying to use a transparent PNG as the icon for my Java application. The image on the JFrame and task bar work great. However, when I use the image with a TrayIcon, I get a black matte background around the edge of the PNG.
Has anybody else come across this issue? I would really like to use a PNG instead of GIF or JPEG.
With Java6, a PNG picture should be used for TrayIcon, but as mentioned in this SO question, check:
the background color chosen to represent the transparent pixels
the transparency options
the resolution of the icon
alternate format like SVG (provided you are using external library like Batik, and conversion mechnism to java.awt.Image)