Do Java Canvas Objects stretch (anti-alias) images like the HTML Canvas Object?

twitter logo github logo ・1 min read

I was wondering if Java Canvas Objects also do that anti-aliasing thing, so when I port RuntDeale to Java it will look stretched, or to the original textures (with / without) scaling.

twitter logo DISCUSS (4)
markdown guide

I wouldn't use Java canvas in the first place, it's outdated and JPanel from Swing is more versatile. However Java's stretching with both is more versatile; every time you use the getScaledInstance() function of the Image object you have to specify the scaling technique (SCALE_FAST, SCALE_DEFAULT, SCALE_AREA_AVERAGING, SCALE_SMOOTH, and SCALE_REPLICATE) which will either antialias or duplicate based on the parameter.


AND which ones don't do anti-alias the image?


I only do pixelated games that look retro so I've only ever had to use SCALE_FAST which gives little to no image scaling, but most others will put some blur on it to make it look smoother (SCALE_SMOOTH and SCALE_DEFAULT) while SCALE_AREA_AVERAGING will make it fairly blurry. Don't know what REPLICATE does, never had to use it.

Classic DEV Post from Oct 11 '19

What was your win this week?

Got to all your meetings on time? Started a new project? Fixed a tricky bug?

PDS OWNER CALIN (Calin Baenen) profile image
I am a 13 (as of Oct 30 of 2019) yr/o developer (I have been developing mini-projects for 4, years now, since I was 9), who makes projects in languages like: Java, HTML, Python 3, JS, CSS, and C#.

Night owl? 🦉

dev.to now has a dark version (in public beta).

Go to the "misc" section of your settings and select night theme ❤️