BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-18-2007, 04:19 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation zoom in the text on the image

Please Login to Remove!

Hi,everyone:

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 .
Code:
public void OpenFile()
    {
        
        try {
            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.
            if (fconn.exists()) 
            {
                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.setColor(0xFF0000);                
                myGraphics.drawText("myText", 20, 5); 
                BitmapField picture = new BitmapField(b);    
                ………………//show the picture
            }
            else            
            {                
                System.out.println("Picture does not exist");
            }
            fconn.close();            
        }
        catch (Exception ioe) 
        {
            System.out.println("Error");
        } 
  }
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!!
Offline  
Old 09-18-2007, 11:06 AM   #2 (permalink)
New Member
 
Join Date: Sep 2007
Model: 7100
PIN: N/A
Carrier: Vodafone
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is not very robust code (Bitmap dimensions must be even) and I got the Alpha wrong but it sort of does the job.

Code:
    public static Bitmap getHalfScale( Bitmap bitmap )
    {
        int height, width, red, green, blue, alpha;
        int[] pixelInput;
        int[] pixelOutput;
        
        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() );

        return result;
    }
    
    public static int indexFromCoordinates( int x, int y, int width )
    {
        int result;
        result = y * width + x;
        return result;
    }
Offline  
Old 09-19-2007, 01:05 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!
Offline  
Old 09-19-2007, 01:09 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Last edited by streamh : 09-19-2007 at 01:11 AM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

MSA ALTAIR® 4 Multigas Detector Monitor, LEL, O2, CO, H2S
$315.0
MSA ALTAIR® 4 Multigas Detector Monitor, LEL, O2, CO, H2S  pictureMSA ALTAIR® 4 Multigas Detector Monitor LEL, O2, CO, H2S
$275.0
MSA ALTAIR® 4 Multigas Detector Monitor LEL, O2, CO, H2S pictureMSA 10116924 ALTAIR 5X 4 GAS MONITOR-LEL O2 CO AND H2S
$599.0
MSA 10116924 ALTAIR 5X 4 GAS MONITOR-LEL  O2  CO  AND H2S pictureMSA Galaxy GX2 calibration station for Altair w/cylinder holder
$1500.0
MSA Galaxy GX2 calibration station for Altair  w/cylinder holder pictureMSA Altair 5x Multi Gas LEL Air Monitor Confined Space Tool Due For Calibration
$174.99
MSA Altair 5x Multi Gas LEL Air Monitor Confined Space Tool Due For Calibration  picture






Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.