Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Problem in displaying images using grid field manager

If i took an image og smaller size the code is working well but if i want to display the camera image its not displaying image with proper width and height.So i want to display the camera images into table format.

 

Here is the code.

 

 

 

VerticalFieldManager manager = (VerticalFieldManager) getMainManager();


     grid = new GridFieldManager(5, 4, GridFieldManager.FIXED_SIZE);

     manager.add(grid);
     int columnWidth = (Display.getWidth() / 4)+10
             - grid.getColumnPadding();
     for ( i = 0; i < 4; i++) {
         grid.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
     }

     BitmapField[] images = new BitmapField[20];
     EncodedImage Icon = null;
     for (i = 0; i < 20; i++) {




         images[i] = new BitmapField(fileImage(), Field.FIELD_HCENTER
                 | Field.FIELD_VCENTER | Field.FOCUSABLE) {


             protected void layout(int width, int height) {
        
                 setExtent(200, 200);

                 }



             protected void paint(Graphics graphics) {

                 super.paint(graphics);


                  graphics.drawText(null, 0,
                  getBitmapHeight(), 2, getBitmapWidth() + 20);


             }

         };

         
         grid.setPadding(10, 0, 0, 0);
         grid.setRowPadding(20);
         images[i].setPadding(20, 10, 5, 10);
         grid.add(images[i]);


     }
 }
     
     public Bitmap fileImage()
     {
         FileConnection fileConnection;
         InputStream inputStream;
         Bitmap bitmap=null;
         try
         {
             fileConnection=(FileConnection)Connector.open("file:///store/home/user/camera/1.jpg",Connector.READ);
             
         
             inputStream=fileConnection.openInputStream();           
             byte[] data=new byte[(int)fileConnection.fileSize()];           
             data=IOUtilities.streamToBytes(inputStream);
             inputStream.close();
             fileConnection.close();
          
             bitmap=Bitmap.createBitmapFromBytes(data,0,data.length,6);
             
             
             
             
         }
         
         catch(IOException e)
         {
             System.out.print(e.getMessage());
         }
         return(bitmap);
     }

 

 

Thanks in advance

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in displaying images using grid field manager

So you will have to scale your camera images to a suitable size - look at Bitmap.scaleInto for help doing this.

 

Have you resolved this similar problem?

http://supportforums.blackberry.com/t5/Java-Development/Problem-in-encodedimage/m-p/2303237

Please use plain text.