I'm trying to print a smooth curve but it seems that some of the pixels are stretched. I tried to debug this by printing the pixel array but it looked smooth. The JPanel created has width and height 800.
This is the printed pixels of the double array:
This is the image drawn:
I have found this function that does the same thing and is really smooth but I want to figure out how to make this from an array of pixels.
grf.drawRoundRect(50, 50, 400, 400, 200, 200);
public void draw(){
Graphics grf = screen.get_graphics();
int width = 400;
int height = 400;
int scale = 1;
BufferedImage red_fill = BufferedImageFactory.fill(width, height, Color.RED);
Matrixi2d square_mask = new Soft_Square().get_filled_in_mask(width, height);
BufferedImage hue_soft_square = square_mask.mask_image(red_fill);
grf.drawImage(hue_soft_square, 50, 50, null);
}
public BufferedImage mask_image(BufferedImage input){
//BufferedImage result = new BufferedImage(width + edge*2, height + edge*2, BufferedImage.TYPE_INT_ARGB);
BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
//for(int x = edge, mask_x = 0; x < width; x++, mask_x++){
//for(int y = edge, mask_y = 0; y < height; y++, mask_y++){
for(int x = 0, mask_x = 0; x < width; x++, mask_x++){
for(int y = 0, mask_y = 0; y < height; y++, mask_y++){
if(get(mask_x, mask_y) != 0){
int mask_alpha = get(mask_x, mask_y);
int color = input.getRGB(x, y);
int red = (0xFF & ( color >> 16));
int alpha = (0xFF & (color >> 24));
int blue = (0xFF & (color >> 0 ));
int green = (0xFF & (color >> 8 ));
//System.out.println("mask value: "+get(mask_x, mask_y));
//System.out.println("initial alpha: " + alpha);
alpha = (int)(alpha * mask_alpha / 255.0);
int sum = ((alpha & 0xff) << 24 | (red & 0xff) << 16 | (blue & 0xff) << 8 | (green & 0xff));
//System.out.println("alpha: " + alpha);
//System.out.println("mask alpha: " + mask_alpha);
result.setRGB(x, y, sum);
//System.out.println("setting result: "+sum);
}
}
}
return result;
}
Edit: Downloading the image shows that the BufferedImage doesn't have the stretching. How do you eliminate the stretching in JPanel? Here's the BufferedImage as png
Edit: This SO-Question fixed the problem.