Skip to main content

Posts

Showing posts with the label Bitmap

Screen capture and save to SDCard in Blackberry Java (OS4.3 and above)

Blackberry OS (4.3 and above) provides a very easy way to capture screen of device. We can use screenshot(Bitmap bmp) method of Display class. In this post you will see how to capture screen contents and save to a file on SDCard. First we will get width and height of screen. This is very important because Bitmap we pass to screenshot method must have same width and height as of screen. int screenWidth=Display.getWidth(); int screenHeight=Display.getHeight(); Next, create a Bitmap object of dimensions equivalent to width and height of screen. Bitmap bmpScreen=new Bitmap(screenWidth,screenHeight); Take screenshot using screenshot method of Display class Dispaly.screenshot(bmpScreen); Now bmpScreen contains our screen image data. Our next task is to save this data in a file on SDCard. Let's create PNGEncodedImage from this Bitmap. PNGEncodedImage imgToSave=PNGEncodedImage.encode(bmpScreen); Open a file to write this image FileConnection fc=(FileConnection)Connector...

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 ...