BlackBerry Application Development Guide using image object plotting (1)

Source: Internet
Author: User

Graphics objects allow applications to perform plotting and plotting rendering) operations. Use the Graphics class to draw the entire screen or a BitmapField. If your application does not contain any field, call Screen. getGraphics) to obtain the drawing context of the entire Screen.

To draw a specified BitmapField, the application passes in a field to the Graphics constructor to obtain a drawing context for a specified field. when a BitmapField is drawn, the field manager transfers a drawing context to the field during field re-painting. To create a custom field, override the Graphics. paint () method when you extend the Field class.

The Graphics class allows you to draw images, such as arcs, straight lines, rectangles, and circles.

Use graphical Context

To draw using the Graphics class, a graphical context is obtained for each field or the entire screen.

To obtain a graphic context for each Field, Graphics constructor is called.

 
 
  1. Bitmap  surface  =  new Bitmap(100,  100);  
  2. BitmapField  surfaceField  =  new BitmapField  (surface);  
  3. Graphics  graphics  =  new Graphics(surface); 

To obtain a graphical context for the entire Screen, call Screen. getGraphics ).

 
 
  1. Graphics  graphics  =  Screen.getGraphics(); 

To use any graphical context drawing, you must complete their painting within the boundaries of the field or screen.

 
 
  1. graphics.fillRect(10,  10,  30,  30);  
  2. graphics.drawRect(15,  15,  30,  30); 

If your image context is not applied to the entire screen, add BitmapField to the screen.

 
 
  1. mainScreen.add(surfaceField); 
Create an interface consistent with the standard BlackBerry UI

The DrawStyle interface provides interfaces for Graphics and Field objects. The implementation of DrawStyle allows you to create an interface consistent with the standard BlackBerry UI. If you are extending the Field class to create a custom Field, your code needs to accept the appropriate style, so it is similar to the standard BlackBerry Application.

DrawStyle is applied to the field as the style parameter, as shown in the following example:

 
 
  1. ButtonField  buttonField  =  new ButtonField(DrawStyle.ELLIPSIS); 

You can use the DrawStyle element in the following objects:

◆ BitmapField

◆ ButtonField

◆ DateField

◆ Graphics

◆ LabelField

◆ ObjectListField

Draw with color

Color Rendering is applicable only to BlackBerry devices on the color screen. To determine whether the BlackBerry device supports color display, Call Graphics. isColor (). To determine the color pixels supported by the BlackBerry device, Call Graphics. numColors ).

Set alpha Value

The global alpha value determines the transparency of the pixels in the painting area. 00x0000) is completely transparent and invisible. 2550x00FF) is completely opaque. To set or obtain the global alpha value, Call Graphics. setGlobalAlpha) or Graphics. getGlobalAlpha ).

(Note: BlackBerry uses the alpha value for a specific grating operation. Text and drawing operations are not used .)

Determine the support of grating operations

To determine whether a Graphics object supports a specific grating operation, Call Graphics. isRopSupported (int) and use one of the following constants as the parameter.

Draw a Path)

To draw a set of shadow filling paths, Call Graphics. drawShadedFilledPath ():

 
 
  1. public void  
  2. drawShadedFilledPath(  
  3. int []  xPts,  
  4. int []  yPts,  
  5. byte []  pointTypes,  
  6. int  []  colors,  
  7. int  []  offsets) 

The following example shows a mixed path from blue to red.

 
 
  1. Bitmap  surface  =  new Bitmap(240,  160);   
  2.  BitmapField  surfaceField  =  new BitmapField(surface);   
  3.  add(surfaceField);    
  4. Graphics  graphics  =  new Graphics(surface);   
  5.  int []  X_PTS  =  {  0,  0,  240,  240  };  
  6.  int []  Y_PTS  =  {  20,  50,  50,  20  };  
  7. int []  drawColors  =  {  0x0000CC,  0x0000CC,  0xCC0000,  0xCC0000  };  
  8. try {graphics.drawShadedFilledPath(X_PTS,  Y_PTS,  null ,  drawColors , null);  
  9. }  
  10. catch  (IllegalArgumentException  iae){System.out.println("Bad  arguments.");} 

Use the drawing format

To enable or disable the drawing format, Call Graphics. setDrawingStyle (int drawStyle, Boolean on). Here, on specifies whether to enable true or disable (false) painting format. to determine whether a drawing format has been set, Graphics is called. isDrawingStyleSet (int drawStyle ).

Use a monochrome bitmap field like a print

By submitting opaque areas with colors, the STAMP_MONOCHROME option allows applications to use a monochrome bitmap, just like printing. This option is used for bitmap. This bitmap is 1-bit and has a defined alpha.

 
 
  1. BitmapField field = new BitmapField(original,  
  2. BitmapField.STAMP_MONOCHROME); 

Draw an image of data that has never been processed

1. Create an empty bitmap. In this example, both the type and size are copied to an existing bitmap.

2. Use the new bitmap to create a Graphics object as the drawing surface.

3. Call Graphics. rawRGB () and draw a new image using unprocessed data from the source.

 
 
  1. Bitmap  restored  =  new Bitmap(original.getType(),  original.getWidth(),  
  2. original.getHeight());  
  3. Graphics  graphics  =  new Graphics(restored);  
  4. try   {  
  5. graphics.drawRGB(argb,  0,  restored.getWidth(),  0,  
  6. 0,  restored.getWidth(),  
  7. restored.getHeight());  
  8. }  
  9. catch (Exception  e)  
  10. {  
  11. System.out.println("Error  occurred  during  drawing:  "  +  e);  
  12. }  

Use bitmap

(Note: The following information about the bitmap type only provides the type information. The application should not rely on the actual bit format of the bitmap as the format, because the future version of the software on the handheld device may change .)

To determine the Bitmap type, call Bitmap. getType (). This method returns one of the following constants:

◆ On BlackBerry devices with black and white screens, data is stored in columns. Therefore, Bitmap. getType () returns COLUMNWISE_MONOCHROME. The first two bytes represent the first 16 pixels in the first column of the bitmap.

◆ Data is stored in the row on the BlackBerry device of the color screen. Therefore, if itmap. getType () is a black/white image, ROWWISE_MONOCHROME is returned, and ROWWISE_16BIT_COLOR is returned for the color image. In a black-and-white image, the first two bytes represent the first 16 pixels of the first line of the bitmap, from left to right. In a color image, the first two bytes represent the first pixel.

The following two Bitmap constructors allow you to specify a type parameter:

◆ Bitmap (int type, int width, int height)

◆ Bitmap (int type, int width, int height, byte [] data)

To obtain the default bitmap type of the BlackBerry device, call the static method:

Bitmap. getDefaultType ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.