Skip to main content

Posts

Showing posts with the label load image

Resizing image in Blackberry 10 Cascades

In this post we will learn how to re-size an image stored on file or in memory. Cascades provide Image class to perform loading of images but it do not have any support for manipulating the image especially re-sizing of image. But we have a class QImage from Qt that support re-sizing of images. So first lets see how we can load image through QImage class Loading image QImage has many overloaded constructors for loading images from different sources or just create an empty QImage of given height and width. We will cover two constructors here, one for loading image from file and other to load image from image data in memory. Loading from file We will use a constructor that takes file name (QString) as a parameter. We can optionally pass format as a char* parameter but its better to skip that so QImage will detect format from the filename QImage img("asset:///testimage.jpg"); Loading from in memory data QImage provides another constructor to load image data stored ...

Drag and Move image using jQuery and crop using PHP - Part2

In Part 1 we discussed how to make image draggable using simple jQuery. In this part we will learn how to save the dragged image using PHP . We will crop the part that is outside our  view port div (which is of resolution 850x600 ). First retrieve the original width and height of image. To do this we will use getimagesize function of PHP . It takes file path as input and return the array containing width at index 0 and height at index 1 $file_path="movable.jpg" $size=getimagesize($file_path); $width=$size[0]; $height=$size[1]; Get current x and y of image. In the HTML FORM written in Part 1 we have hidden fields with name locationX and locationY containing X and Y co-ordinates respectively. $x=$_POST["locationX"]; $y=$_POST["locationY"]; Next step is to check if any part of image is outside our bounding box (div). We will do this separately for width(horizontal view) and height (vertical view). For horizontal view If sum of curren...

Resizing image in C#

In this blog post I will explain in short how to load and re size an image in C# and save the resulting image in a file. Actually the process is very easy. Lets break it in chunks Loading image from a file .NET has multiple ways to load an image. 1) From a file 2) From a Stream object 3) From a GDI Bitmap object For this post we will only load image from a File.Loading image from file is straight forward. It requires calling static method FromFile of Image class , passing the file path as a parameter. Here is how Image myImage=Image.FromFile(sourcePath); Re-sizing image As we now have Image instance we have to re size it. For re-sizing we will use one overload of Bitmap class constructor which takes Image instance and new width and height for scaling. So here is the one liner to do this job Bitmap bmp=new Bitmap(myImage,newWidth,newHeight); Saving the resulting image We have a Bitmap containing scaled version of our original image.Now we will save it to a ...