[java] Graphics.drawImage()
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?
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):
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.
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement