Graphics2D.scale() producing pixelated images from vectors
I have a set of JPanels that I am using in my game to display the interface. Each one overrides paintComponent() and draws itself using Java2D. That all works great -- you can zoom in, move around, etc. and it all looks very nice and uses affine transformations.
I'm trying to produce very high resolution images from this interface (for use on a poster) and using scale() is creating pixelated images rather than nice, high res images of the vector data.
My code works as follows:
1.) Create an instance of the interface using some saved game state data.
2.) Create a Graphics2D object from a BufferedImage object.
3.) Scale the Graphics2D object so that the interface will fill the entire image (in my test cases, the interface is running at 800x600 normally, and the resulting image is going to be 3200x1600, so a 4x scale).
4.) Call the interface's paint method on the Graphics2D object. Note that all of the paint methods are using calls to fill... and draw...; nothing is getting rasterized in my code.
5.) Write out the image object to a file (PNG).
A sample of the output is here:
http://i176.photobucket.com/albums/w174/toupsz/ScreenShot2007-04-24_11-45-35_-0500.png
The white circle in the upper left hand corner is drawn in between steps 4 and 5. It actually looks correct.
Is there something I'm doing wrong? Is it a deficiency in Java itself? Is there some way to fix it?
Any help would be most appreciated!
Thanks!
-Zach
Message was edited by:
aaasdf
Try setting a few hints on your Graphics2D:
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Similar Messages
-
How to create a georaster image from vector polygons
I want to create a georaster image from polygons. I know i can use it gdal_rasterize utility but want to find out if i can do it within Oracle itself. Are there any vector or georaster functions i can use?
Hi, there is no such functions within oracle to do that. thanks.
-
Pixelated images from iPhoto for iPad
iPhoto for iPad is a fantastic application, but very often although the images I edit look ok within the application, when I look at them in any other application (including apple's own built in photo browser) they are heavily pixelated, or some parts of them are missing altogether. The same thing happens when I beam or email said photos to my Mac.
I tried uninstalling and then reinstalling the app, I even went so far as to restore my iPad (non jail broken iPad 2, 64Gb, WiFi+3G, running iOS 5,1,1) from a backup, but the problem persists.
Any suggestions would be welcome.
ChrisDah.veed
In the Photo app on the iPad in the Photos tab > Edit I can select pix, but the red Delete button is greyed out??? Puzzled.
Is there any other way to delete a range of pictures or an Album in the Photo app (or in the iPhoto for iPad app)???
Any advice would be appreciated. Thanks. -
Vector Images from iStockphoto
Just wondering if I should be able to open and edit vector
images from iStockphoto in Fireworks?
Like this one :
example
vector image
Or do I need Photoshop?
Cheers.Those should come from iStock in the EPS format. From the
Fireworks help file:
Fireworks opens most EPS files, such as Photoshop EPS files,
as flattened bitmap images, in which all objects are combined on a
single layer. Some EPS files exported from Illustrator, however,
retain their vector information.
When you open or import most EPS files, the EPS File Options
dialog box opens.
Image Size
determines the image dimensions and the units in which the
image is rendered. You can select from pixels, percent, inches, and
centimeters.
Resolution
indicates the pixels per unit for the resolution.
Constrain Proportions
opens the file in the same proportions as the original.
Anti-aliased
smoothes jagged edges in the opened EPS file.
When you open or import Illustrator EPS files that contain
vector information, the Vector File Options dialog box opens. This
is the same dialog box that appears when you open or import
FreeHand files. -
How to create Image from 8-bit grayscal pixel matrix
Hi,
I am trying to display image from fingerprintscanner.
To communicate with the scanner I use JNI
I've wrote java code which get the image from C++ as a byte[].
To display image I use as sample code from forum tring to display the image.
http://forum.java.sun.com/thread.jspa?forumID=20&threadID=628129
import java.awt.*;
import java.awt.color.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
public class Example {
public static void main(String[] args) throws IOException {
final int H = 400;
final int W = 600;
byte[] pixels = createPixels(W*H);
BufferedImage image = toImage(pixels, W, H);
display(image);
ImageIO.write(image, "jpeg", new File("static.jpeg"));
public static void _main(String[] args) throws IOException {
BufferedImage m = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY);
WritableRaster r = m.getRaster();
System.out.println(r.getClass());
static byte[] createPixels(int size){
byte[] pixels = new byte[size];
Random r = new Random();
r.nextBytes(pixels);
return pixels;
static BufferedImage toImage(byte[] pixels, int w, int h) {
DataBuffer db = new DataBufferByte(pixels, w*h);
WritableRaster raster = Raster.createInterleavedRaster(db,
w, h, w, 1, new int[]{0}, null);
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel cm = new ComponentColorModel(cs, false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
return new BufferedImage(cm, raster, false, null);
static void display(BufferedImage image) {
final JFrame f = new JFrame("");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JLabel(new ImageIcon(image)));
f.pack();
SwingUtilities.invokeLater(new Runnable(){
public void run() {
f.setLocationRelativeTo(null);
f.setVisible(true);
And I see only white pixels on black background.
Here is description of C++ method:
GetImage
Syntax: unsigned char* GetImage(int handle)
Description: This function grabs the image of a fingerprint from the UFIS scanner.
Parameters: Handle of the scanner
Return values: Pointer to 1D-array, which contains the 8-bit grayscale pixel matrix line by line.
here is sample C++ code which works fine to show image in C++
void Show(unsigned char * bitmap, int W, int H, CClientDC & ClientDC)
int i, j;
short color;
for(i = 0; i < H; i++) {
for(j = 0; j < W; j++) {
color = (unsigned char)bitmap[j+i*W];
ClientDC.SetPixel(j,i,RGB(color,color,color));
Will appreciate your help .Hi Joel,
The database nls parameters are:
select * from nls_database_parameters;
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET CL8MSWIN1251
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 9.2.0.4.0
Part of the email header:
Content-Type: multipart/alternative; boundary="---=1T02D27M75MU981T02D27M75MU98"
-----=1T02D27M75MU981T02D27M75MU98
-----=1T02D27M75MU981T02D27M75MU98
Content-Type: text/plain; charset=us-ascii
-----=1T02D27M75MU981T02D27M75MU98
Content-Type: text/html;
-----=1T02D27M75MU981T02D27M75MU98--
I think that something is wrong in the WWV_FLOW_MAIL package. In order to send 8-bit characters must be used UTL_SMTP.WRITE_ROW_DATA instead of the UTL_SMTP.WRITE_DATA.
Regards,
Roumen -
My iphone 4s suddenly displays images from Yahoo, Google, and Flickr at a low resolution. I have IOS 7.0.4. My phone camera works fine, but any web based photo content from Safari, Yahoo images, Google images, and Flickr all come in pixelated and low res. What's the deal?
It happened to me but later I figured out that cellular signal was not that great and so the Internet was very slow. It took me about 2 minutes to get the full resolution picuture on either of the app you've described. Try to get faster internet either by wifi or good signal and then check.
-
If you change the image mode of this image from 8-bit RGB image to Grayscale
mode while in PSCS – what will the new Pixel Count be?If you mean by Pixel count the number of pixels, this will not change. The image will have the same size thus the same number of pixels.
-
How to create an Average Image from Gray Scale (8 bits) JPEG Images
I�m trying to create a mean image from 9 JPEG Images, but this mean image has lots of "noise", is distorced, and doesnt�resemble at all the original ones.
I need this mean image so I�ll correlate each of the original ones to find out the best image I�m going to choose ussing NCC (normalized cross correlation coeficient).
When I use setRGB(x,y,rgb), it returns diferent "images" according to the number of zeros, for ex.: rgb = 028028028 is different from 28028028 and from 282828. I can�t find a way to work it out.
My algorithm is the folowing:
File f;
double [] [] pixels = null;
Color [] [] tempPixel = null;
Integer [] [] byte0 = null;
Integer [] [] byte1 = null;
Integer [] [] byte2 = null;
Integer [] [] byte3 = null;
Integer [] [] tempPixels = null;
mean = null;
int w,h;
fileNames = new String[numFrames];
for (int i=1; i<numFrames; i++){
fileName = path + "Frame#" + i + ".jpg";
fileNames[i-1] = fileName;
// just for getting width, height, for configuring pixels array and
// buffered images - mean & best.
fileName = path + "Frame#8.jpg";
f= new File(fileName);
try{
temp = ImageIO.read(f);
}catch(IOException io){ return false;}
w = temp.getWidth();
h = temp.getHeight();
mean = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
pixels = new double [w][h];
byte0 = new Integer [w][h];
byte1 = new Integer [w][h];
byte2 = new Integer [w][h];
byte3 = new Integer [w][h];
tempPixel = new Color[w][h];
tempPixels = new Integer[w][h];
f=null; temp = null;
//reset pixels values.
for(int x = 0; x < w; x++){
for(int y = 0; y < h; y++){
byte0[x][y] =0;
byte1[x][y]=0;
byte2[x][y]=0;
byte3[x][y] = 0;
pixels[x][y] = 0;
// read each file (image), and according to W & H and collects the
// pixels values.
for(int j=0; j<numFrames-1; j++) {
f = new File(fileNames[j]);
try{
temp = ImageIO.read(f);
}catch(IOException io){ return false;}
if(temp!=null)
for(int x=0 ; x< temp.getWidth(); x++){
for(int y=0; y<temp.getHeight(); y++){
tempPixel[x][y] = new Color(temp.getRGB(x,y));
pixels[x][y] = pixels[x][y] + temp.getRGB(x,y) / 16581375;
//BLUE
byte0[x][y] = byte0[x][y] + (tempPixel[x][y].getBlue());//tempPixel[x][y].getBlue(); //& 0xff;
//GREEN
byte1[x][y] = byte1[x][y] + (tempPixel[x][y].getGreen());// >>8 & 0xff;
//RED
byte2[x][y] = byte2[x][y] + (tempPixel[x][y].getRed()); //>>16 & 0xff;
//ALPHA
byte3[x][y] = byte3[x][y] + (tempPixel[x][y].getAlpha()); //>>24 & 0xff;
f=null;
}//end of loop for j<numFrames
String t0, t1, t2, t3;
for(int x=0 ; x< temp.getWidth(); x++){
for(int y=0; y< temp.getHeight(); y++){
byte0[x][y] = byte0[x][y] / numFrames;
if((byte0[x][y])<10)
t0= "0" + byte0[x][y].toString();
//else if((byte0[x][y])>=10 & ((byte0[x][y])<100))
// t0 = "0" + byte0[x][y].toString();
else
t0 = byte0[x][y].toString();
byte1[x][y] = byte1[x][y] / numFrames;
if((byte1[x][y])<10)
t1= "0" + byte1[x][y].toString();
//else if((byte1[x][y])>=10 & ((byte1[x][y])<100))
// t1= "0" + byte1[x][y].toString();
else
t1 = byte1[x][y].toString();
byte2[x][y] = byte2[x][y] / numFrames;
if((byte2[x][y])<10)
t2= "0" + byte2[x][y].toString();
//else if((byte2[x][y])>=10 & ((byte2[x][y])<100))
// t2 = "0" + byte2[x][y].toString();
else
t2 = byte2[x][y].toString();
byte3[x][y] = byte3[x][y] / numFrames;
if((byte1[x][y])<10)
t3="0" + byte3[x][y].toString();
else
t3 = byte3[x][y].toString();
pixels[x][y] = (pixels[x][y]/numFrames) * 16581375;
try{
String rgbs = t2+t1+t0;
Integer rgb = Integer.valueOf(rgbs);
//System.out.println("Valor do rgb: " +rgb);
mean.setRGB(x,y,(int)pixels[x][y]);
}catch(NumberFormatException nfe){
System.out.println("ERROR: Integer to STRING: " + nfe);
return false;
}// end of catchIt�s ok, I�ve already found the solution.
Thanks. -
Problem creating image from a data vector
Hello i have a problem in this aplication.
I get a image from a web cam. I want to put the original image in a file and the negative image in another file (in this example is not the negative image, is just a white image). The problem is when i use setData method. The image become black. If I use setFormat method the new image is the original image.
Here is the code with problems:
imageBuffer = frameGrabbingControl.grabFrame();
theData = new int[dataLength];
theData = (int[]) imageBuffer.getData();
for (int y = 0; y < videoHeight - imageScanSkip; y+=imageScanSkip) {
for (int x = 1; x < videoWidth - imageScanSkip; x+=imageScanSkip)
theData[y*videoWidth+x]=Integer.parseInt("FFFFFF",16);
Buffer b1=new Buffer(); //This is the new buffer in which i want to put the new pic
b1.setData(theData);
//here i create the 2 files frst from the original buffer and second from the new buffer b1
Image img = (new BufferToImage((VideoFormat)imageBuffer.getFormat()).createImage(imageBuffer));
Image img1 = (new BufferToImage((VideoFormat)b1.getFormat()).createImage(b1));
BufferedImage buffImg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
BufferedImage buffImg1 = new BufferedImage(320,240, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
Graphics2D g1 = buffImg1.createGraphics();
g.drawImage(img, null, null);
g1.drawImage(img1, null, null);
try{
ImageIO.write(buffImg, "jpg", new File("c:\\webcam.jpg"));
ImageIO.write(buffImg1, "jpg", new File("c:\\webcam1.jpg"));
catch (Exception e){}
the webcam1.jpg file is black(it should be white).
If i put "b1.setFormat(imageBuffer.getFormat());" the webcam1.jpg will be same the file as webcam.jpgHello i have a problem in this aplication.
I get a image from a web cam. I want to put the original image in a file and the negative image in another file (in this example is not the negative image, is just a white image). The problem is when i use setData method. The image become black. If I use setFormat method the new image is the original image.
Here is the code with problems:
imageBuffer = frameGrabbingControl.grabFrame();
theData = new int[dataLength];
theData = (int[]) imageBuffer.getData();
for (int y = 0; y < videoHeight - imageScanSkip; y+=imageScanSkip) {
for (int x = 1; x < videoWidth - imageScanSkip; x+=imageScanSkip)
theData[y*videoWidth+x]=Integer.parseInt("FFFFFF",16);
Buffer b1=new Buffer(); //This is the new buffer in which i want to put the new pic
b1.setData(theData);
//here i create the 2 files frst from the original buffer and second from the new buffer b1
Image img = (new BufferToImage((VideoFormat)imageBuffer.getFormat()).createImage(imageBuffer));
Image img1 = (new BufferToImage((VideoFormat)b1.getFormat()).createImage(b1));
BufferedImage buffImg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
BufferedImage buffImg1 = new BufferedImage(320,240, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
Graphics2D g1 = buffImg1.createGraphics();
g.drawImage(img, null, null);
g1.drawImage(img1, null, null);
try{
ImageIO.write(buffImg, "jpg", new File("c:\\webcam.jpg"));
ImageIO.write(buffImg1, "jpg", new File("c:\\webcam1.jpg"));
catch (Exception e){}
the webcam1.jpg file is black(it should be white).
If i put "b1.setFormat(imageBuffer.getFormat());" the webcam1.jpg will be same the file as webcam.jpg -
Why can't I copy an image or vector from Illustrator CC and paste to Fireworks CS6?
Why can't I copy an image or vector from Illustrator CC and paste to Fireworks CS6? This was possible with Illustrator CS6. I know they are different versions but since there is no Fireworks CC, is there a fix update???
Yes, other users have complained about that. Unfortunately, Fireworks' development was halted a year ago, and I would be surprised if Adobe spends any money or time to fix bugs and interoperability issues in Fireworks. I would not expect any real updates or fixes.
Tough to swallow, but FW is dead in the water and EOL'ed. -
Reading pixel color from Image?
Hello frnds,
I am making a project in which i have to upload Image, am trying to find color of each pixel in RGB format so that I can locate where my sprite begins in Image !!
But I am not able to do so.. do I have to use PixelGrabber to do that? or should i use RGBImageFilter..!! I am new to java so if u can tell me how to use them, then It would be grateful.
I want to scan whole image from left to right, Right to left, top to bottom and vice-versa. So that I can exactly tell at what pixel value sprite starts and ends.
Please help me out. any sort of help will be useful for my project..
Thanking you in advance.Image bufferImage;PixelGrabber pg1;
public boolean fetchPixels(byte[] jpegData, int[] pixelData)
try
bufferImage = Toolkit.getDefaultToolkit().createImage(jpegData);
// this may not be required unless asynchronous, but seems to do no harm
MediaTracker mt = new MediaTracker(jcamData);
mt.addImage(bufferImage, 0);
try
mt.waitForID(0);
catch(InterruptedException e)
e.printStackTrace();
if(mt.isErrorAny()==true)
System.out.println("Exception fetchPixels "+"createImage failed");
// flush anything in bufferedImage
if(bufferImage!=null)bufferImage.flush();
return false; // and pixelData not updated
Thread.yield();
pg1 = new PixelGrabber(bufferImage, 0, 0, camWidth, camHeight, pixelData, 0, camWidth);
try{pg1.grabPixels();}catch(InterruptedException e){}
Thread.yield();
// flush bufferedImage as no longer needed, and so not to be in memory cache for next image load
if(bufferImage!=null)
bufferImage.flush();
catch(Exception e){System.out.println("Exception fetchPixels "+e);}
return true;
} -
Convert colour images to grayscale images & get pixel data from them
Is the code below correct to convert colour images to grayscale images in Java?
public void convertToGrayscale (String sourceName,String destName) throws Exception {
JPEGImageDecoder decoder=JPEGCodec.createJPEGDecoder(new FileInputStream(sourceName));
JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(new FileOutputStream(destName));
BufferedImage sourceImg=decoder.decodeAsBufferedImage();
BufferedImageOp op =new ColorConvertOp(
ColorSpace.getInstance(ColorSpace.CS_GRAY),null);
BufferedImage destImg = op.filter(sourceImg,null);
encoder.encode(destImg);
decoder = null;
encoder = null;
When I get grayscale images from the code below, I would like to access the pixels of those images. So I tried to do:
byte[] dd=((DataBufferByte)mImage.getRaster().getDataBuffer()).getData();
BUT the data result array is not 0-255. Could anyone suggest how to obtain pixel data from grayscale images?
In case that my code shown is not correct or suitable, please give your advice. What I would like to do are in the steps as follows:
1 change 100*70 jpeg-images to 100*70 grayscale images.
2 create two dimensional array of pixel data (example [100][70]) from converted images. The number in the array should be between 0-255, right??? And 0 refers to black colour and 255 refers to white colour???
I am confused about grayscale images. Please help.
Thank you so muchI am not sure i understand what is the problem exactly.
Structure of DataBuffer is described by SampleModel used by same Raster
object. E.g. it might be 1 byte per xipex or 4 bytes per pixel.
In your example convertToGrayscale saves images to file as JPEG and
it seems you later read it back. It is possible what image you read back
is not greyscale but ARGB and data buffer has different format.
Technically, if you just need level of grey you may simply
call getRGB on your output image. Grey is uniform mix of R, G and B.
Also, instead of ColorConverOp you may dimply create output image of
grayscale type and draw your color input image with drawImage().
If none of these helps please try to provide more details. -
Gettin Pixel data from png image
Hi,
Has anyone worked with the byte data returned my the getSnapshot() method of the VideoControl (MMAPI). I believe the default is png( i have tested this on Nokia 3650 and 6600 and on Siemens SX1).
In all the devices that support Nokia UI library i can get the pixel values from the byte data by using the com.nokia.mid.ui library, specifically the DirectGraphics.getPixels() method.
In MIDP 2.0 devices i can do this using the Image.getRGB method.
But what about MIDP 1.0.3 devices that do not have the Nokia library ? i believe that the byte data returned by the camera is of raw png format. I have never done this before and so far my search on the web has not been fruitful.
Can anyone point me to information abt the raw png Image (number of bytes of header ... etc) so that i can write my own code to extract the information or better yet point me to the code that does this.http://www.wotsit.org/
shmoove -
How to create an gray scale png image from intensitie​s values
Hi,
I would like create a gray scale png image from set of intensities values which is saved in excel sheet . Is IMAQ tool necessary for this vi?
thanks & regards
ManojYou posted in the feedback forum, which is not correct for your question. I am guessing you are talking about LabVIEW since you mention "vi".
manojkp89 wrote:
Is IMAQ tool necessary for this vi?
The answer is NO. Plain LabVIEW is sufficient.
LabVIEW Champion . Do more with less code and in less time . -
DVCPRO HD 720P: pixel aspect ratios with still images from Final Cut
I am currently trying to get still images from a trailer I am working on with Final cut pro. The footage is DVCPRO HD 720P 24pn and the interlacing and pixel aspect ratios have been giving me a lot of trouble in photoshop. I am able to convert the PAR but it is for preview purposes only...? I need the file to be saved with the converted PAR. How do you do that???
Also, the de-interlacing filter on photoshop doesn't seem to help the quality of the photo.
Anyone have any ideas?
I have searched and searched and only found somewhat related questions, so maybe I am the only one trying to do this...Why are you doing interlace if you have 720p?
Maybe you are looking for
-
When I click on Firefox the first time it says "Foxfire is installing your updates and will start in a few moments-. (with a green bar)" then it says "Software Update Failed (in blue) with an exclamation mark inside a yellow triangle) The update coul
-
Clear data in sql report region on page load....
I have a sql report region.when i run the page the data getting populate on the screen because of the sql query. On page load i dont want to populate the data in screen. i have created the page process to clear cahe the page. but the data is not clea
-
ITunes freezes when selecting "Add file to library" or "Add folder....
Not had a problem before and everything worked fine. But this morning if I select "Add file to library" or "Add folder to library" nothing happens and itunes just freezes. I can play music already in the library. Any ideas?
-
Preview doesn't recognize CR2 files
Hello, I had recently bought an iMac but I'm unable to open cr2 files when I'm trying to do a double click to open in Yosemite. Although I can open them in Lightroom 5.7 and could not in CS6(understand I need to upgrade it). I know there should be a
-
Automate to Sequence - Set To Unnumbered Markers
I'm using Premier Pro CS3 on a Windows XP machine. I've found that if I select the "Sequentially" Placement Option under "Automate to Sequence" the other option (Set to Unnumbered Markers)in the drop-down box completely disappears (not just grayed ou