Posts

Showing posts with the label Resize

Cross-browser Window Resize Event - JavaScript / JQuery

Answer : jQuery has a built-in method for this: $(window).resize(function () { /* do something */ }); For the sake of UI responsiveness, you might consider using a setTimeout to call your code only after some number of milliseconds, as shown in the following example, inspired by this: function doSomething() { alert("I'm done resizing for the moment"); }; var resizeTimer; $(window).resize(function() { clearTimeout(resizeTimer); resizeTimer = setTimeout(doSomething, 100); }); $(window).bind('resize', function () { alert('resize'); }); Here is the non-jQuery way of tapping into the resize event: window.addEventListener('resize', function(event){ // do stuff here }); It works on all modern browsers. It does not throttle anything for you. Here is an example of it in action.

Android: Resizing Bitmaps Without Losing Quality

Answer : Good downscaling algorithm (not nearest neighbor like) consists of just 2 steps (plus calculation of the exact Rect for input/output images crop): downscale using BitmapFactory.Options::inSampleSize->BitmapFactory.decodeResource() as close as possible to the resolution that you need but not less than it get to the exact resolution by downscaling a little bit using Canvas::drawBitmap() Here is detailed explanation how SonyMobile resolved this task: http://developer.sonymobile.com/2011/06/27/how-to-scale-images-for-your-android-application/ Here is the source code of SonyMobile scale utils: http://developer.sonymobile.com/downloads/code-example-module/image-scaling-code-example-for-android/ Try below mentioned code for resizing bitmap. public Bitmap get_Resized_Bitmap(Bitmap bmp, int newHeight, int newWidth) { int width = bmp.getWidth(); int height = bmp.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleH...