|streamh ||09-18-2007 04:19 AM |
zoom in the text on the image
I'm research on how to zoom in the texts or lines which drawing on the image, and I want to know how to implement it .
public void OpenFile()
FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/pictures/ddd78e99bb07e70d6e068c9b.jpg");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
InputStream input = fconn.openInputStream();
int available = (int)fconn.fileSize();
byte data = new byte[available];
input.read(data, 0, available);
EncodedImage image = EncodedImage.createEncodedImage(data,0,data.length);
image.setScale(2); //zoom out the image to 50%
Bitmap b = image.getBitmap();
Graphics myGraphics = new Graphics(b);//draw a text!
myGraphics.drawText("myText", 20, 5);
BitmapField picture = new BitmapField(b);
………………//show the picture
System.out.println("Picture does not exist");
catch (Exception ioe)
As well know to all , we can zoom in or out the image by image.setScale(). I draw a text on the Bitmap got by the image.getBitmap() , but the when the image is zoomed in or out , the text is not changed , so how could I implement this?
In my opinion, I should change the bitmap b into EncodedImage after I draw the text on it. So I can call the method setScale() to zoom in or out the text with the origin image. But how can I change the bitmap b into EncodedImage?
Does anyone have any suggestions?
Thank you very much!!
This is not very robust code (Bitmap dimensions must be even) and I got the Alpha wrong but it sort of does the job.
public static Bitmap getHalfScale( Bitmap bitmap )
int height, width, red, green, blue, alpha;
width = bitmap.getWidth();
height = bitmap.getHeight();
Bitmap result = new Bitmap( bitmap.getType(), width / 2, height /2 );
pixelInput = new int[width * height];
pixelOutput = new int[result.getWidth() * result.getHeight()];
bitmap.getARGB( pixelInput, 0, width, 0, 0, width, height );
for ( int x = 0; x < width; x += 2 )
for ( int y = 0; y < height; y += 2 )
alpha = 0;
red = 0;
green = 0;
blue = 0;
for ( int dx = 0; dx < 2; dx++ )
for ( int dy = 0; dy < 2; dy++ )
alpha += ( pixelInput[indexFromCoordinates(x+dx,y+dy,width)] & 0xff000000 ) >> 24;
red += ( pixelInput[indexFromCoordinates(x+dx,y+dy,width)] & 0x00ff0000 ) >> 16;
green += ( pixelInput[indexFromCoordinates(x+dx,y+dy,width)] & 0x0000ff00 ) >> 8;
blue += ( pixelInput[indexFromCoordinates(x+dx,y+dy,width)] & 0x000000ff );
alpha >>= 2;
red >>= 2;
green >>= 2;
blue >>= 2;
pixelOutput[indexFromCoordinates(x/2,y/2,result.getWidth())] = 0x70000000 | ( red << 16 ) | ( green << 8 ) | blue;
result.setARGB( pixelOutput, 0, result.getWidth(), 0, 0, result.getWidth(), result.getHeight() );
public static int indexFromCoordinates( int x, int y, int width )
result = y * width + x;
|streamh ||09-19-2007 01:05 AM |
Thank you , pook! I'm pleasure to see your post!
Firstly, for the function getHalfScale , we can only zoom out the bitmap by many pixel operations. I think it may be adding too much compute process comparing with setScale(), of course it's maybe!
Secondly, if we want to zoom in the image, we need to write another image processing algorithm. And obviously , the algorithm of getting the average value of a n*n area is not the best way.
So I think using the system method setScale() maybe is a better way! And I want to change the bitmap b into EncodeImage , how can I do this?
Thank you again for your help!
|streamh ||09-19-2007 01:09 AM |
And there are some bugs on your code!
"x+dx" and "y+dy" maybe bigger than width and height !
And you should make a judgement on whether there is an alpha map associated with this Bitmap by calling hasAlpha() .
|All times are GMT -5. The time now is 09:56 PM. || |
Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.