Jump to content
  • Advertisement
Sign in to follow this  
apocalypstic

[java] Graphics.drawImage()

This topic is 4467 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose I am drawing a 1000*1000 image onto a 100*100 buffer, g.drawImage() will use the pixels from the source image that are nearest to the position to draw to. This causes artifacts and doesnt look nice. Is there a way to draw an image using linear interpolation so that the resultant pixels are blended between the nearest neighbourhood source pixels?

Share this post


Link to post
Share on other sites
Advertisement
Hmmm, can't say I know of an automatic way, but if you use an ARGB int array(or any other direct pixel access type method) you could do it yourself. Something like this (to make each pixel an average of all the pixels it covers):

int minx,miny,maxx,maxy ;
int totalcolor,totalpixels ;
for(int k=0;k<towidth;k++){
for(int j=0;j<toheight;j++){
minx = (fromwidth*(int)x)/towidth ;
miny = (fromheight*(int)y)/toheight ;
maxx = (fromwidth*((int)x+1))/towidth ;
maxy = (fromheight*((int)y+1))/toheight ;
totalcolor = 0 ;
totalpixels=0;
for(int l=minx;l<maxx;l++){
for(int m=miny;m<maxy;m++){
totalcolor+=from[l][m] ;
totalpixels++;
}}
to[k][j] = totalcolor/totalpixels ;
}}



That's assuming each image was a 2 demensional array of pixels with one color component(obviously not likely to be the case) and I just wrote that off the top of my head, but hopefully that'll give you some idea of how to do it.

Share this post


Link to post
Share on other sites
Please be advised that only a small number of handsets actually support images that large, as they eat around 3 Megabytes on the heap!

I don't really get your question... are you drawing the 1k/1k image to fit the smaller buffer, or are you only rendering a 100x100 section of the larger image?

In the latter case, you don't need any filtering, in the former, you need to write it yourself. You might get away with using Nokia's DirectGraphics API on Nokia phones, and JSR-184 on handsets that do support Java 3D with bilinear filtering.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thygrrr
Please be advised that only a small number of handsets actually support images that large, as they eat around 3 Megabytes on the heap!

I don't really get your question... are you drawing the 1k/1k image to fit the smaller buffer, or are you only rendering a 100x100 section of the larger image?

In the latter case, you don't need any filtering, in the former, you need to write it yourself. You might get away with using Nokia's DirectGraphics API on Nokia phones, and JSR-184 on handsets that do support Java 3D with bilinear filtering.


Im rescaling a 1k/1k image onto a smaller canvas.

Yeah I guess Ill have to do it myself. Could be a bit slow though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!