[Recommended] brew-display and Image

Source: Internet
Author: User
Tags bmp image transparent color
A. What image formats does brew support?
Applicable versions: 1.0, 1.1, 2.0
Brew supports any BMP file whose color depth reaches the value provided on the running device. Brew does not currently support GIF and JPEG images. Some devices support GIF and JPEG images. For more information, see the device data table to see if the OEM has supported the expansion of images in the above format or other formats. Brew SDK & reg; 1.1 and later versions support PNG and brew compressed image (BCI) formats. Both SDK 2.0 and later versions support idib. Using idib frees you from calling convertbmp, improving the screen update speed. Brew SDK & reg; 2.1 and later versions support the wbmp format.

In brew SDK & reg; 1.0, the simulator can only simulate BMP with one, four, and eight color depths. SDK 1.1 added support for two-bit color depth BMP simulators; SDK 2.0 added support for 16-bit color depth BMP images simulators.

B. How to generate two-digit images?
Applicable versions: 1.0, 1.1, 2.0
The 2-Bit Tool included in the 2.0 SDK can convert Two-Bit Bitmap and four-bit bitmap. To build a Two-Bit Bitmap for a handheld device that uses gray display, you can use MS paint to select white, black, light gray, and dark gray entries from the palette (typically the first two colors of the first and second rows) to build a bitmap. Save it as a 16-color image, and then use 2bit tool to convert it into a two-bit bitmap.

C. What is the transparent color on the color and monochrome phone?
Applicable versions: 1.0, 1.1, 2.0
In brew 1.x, the purple color is the transparent color of the color device, and the white color is the transparent color of the monochrome and Level 4 gray devices.

In brew 2.0 or later versions, you can use ibitmap_settransparencycolor to change the transparent color. Convertbmp can initialize transparent colors (purple and white) to be compatible with earlier brew versions ). However, bitmap images obtained by other methods do not have a fixed transparent color.

D. How to create an iimage object using a bitmap in the memory?
Applicable versions: 1.0, 1.1, 2.0
Use the ishell interface ishell_loadresimage (for resources) and ishell_loadimage (for files) to complete bitmap loading as resources or files. However, it is sometimes necessary to initialize an iimage object from the memory-for example, when the bitmap content is modified before the display, or when the data is not cached to a file and the image is retrieved through a socket connection.

When the iimage object must be initialized using a bitmap in the memory, the iimage interface iimage_setstream should be used. The following code example illustrates this technology. It obtains the class ID of the BMP image processing program by calling ishell_gethandler, creates a memastream object, and uses it as the bitmap stream in the memory. Note: In this example, the image format is Windows BMP, and "PME-> pbmpdata" points to the start of Windows File Format BMP (bitmapfileheader ).

Sample Code:
Aeeclsid CLS;
Iimage * piimage = NULL;
Imemastream * pmemstream = NULL;

// Determine the class ID of the BMP handler function, and then
// Create an instance of this brew class
CLS = ishell_gethandler (PME-> A. m_pishell, htype_viewer, "image/BMP ");

If (CLS ){
Ishell_createinstance (PME-> A. m_pishell, CLS, (void **) (& piimage ));
}

If (PME-> pbmpdata ){
Ishell_createinstance (PME-> A. m_pishell, aeeclsid_memastream, (void **) (& pmemstream ));
If (pmemstream ){
// Create a memstream and use it as the bitmap stream in the memory.
Imemastream_set (pmemstream, PME-> pbmpdata, sizeof (PME-> pbmpdata), 0, 0 );
Iimage_setstream (piimage, (iastream *) pmemstream );

// Use your iimage method in Normal Mode
Iimage_draw (piimage ,...,...);
Idisplay_updateex (PME-> A. m_pidisplay, true );
}
}

E. How to load images from files or resource files?
By using the ishell interface ishell_loadresimage (for resources) or ishell_loadimage (for files), followed by iimage_draw, it is easy to load and draw images from files or resources. This article demonstrates the basic steps required to use the ishell and iimage interfaces to load and display bitmaps.

To display images from a resource, follow these steps:
1. Create a bitmap.
2. Add it to the resource editor.
3. Compile the. Bar and. H files in the resource editor.
4. Add the. h file to your project.
5. Use ishell_loadresimage to load the image.
6. If the loading operation returns a non-null value, the loading operation is started and the pointer to the image is returned.
Back. This does not mean that the image loading is completed. To understand the image operation completion time, you need
Use iimage_policy () for callback.
7. When the image is loaded, a callback is triggered.
8. Use iimage_draw () to display the image during the callback process.
9. Use idisplay_update () to update the screen.
10. Release the iimage pointer.

To display an image in a file, follow these steps:
1. Use ishell_loadimage to load the image from the file.
2. If the loading operation returns a non-null value, the loading operation is started and the pointer to the image is returned.
Back. This does not mean that the image loading is completed. To understand the image operation completion time, you need
Use iimage_policy () for callback.
3. When the image is loaded, a callback is triggered.
4. Use iimage_draw () to display the image during the callback process.
5. Use idisplay_update () to update the screen.
6. Release the iimage pointer.

Sample Code:
Typedef struct mystruct
{
Aeeapplet;
Iimage * m_pimage;
......
} Mydata;

Enum restype
{
Load_res_from_file,
Load_res_from_res
};

# Define my_res_file "Myres. Bar"
# Define my_image_file "myimg.bmp"

// Load and display a bitmap from a resource and file
Int mydisplayresimage (mydata * PME, restype Rtype)
{
Aeedeviceinfo DM;

If (! PME)
Return efailed;

If (Rtype = load_res_from_res)
{
// Load image from resources
PME-> m_pimage = ishell_loadresimage (
PME-> A. m_pishell,
My_res_file,
Idb_my_color_bitmap );
}
Else // load_res_from_file
{
PME-> m_pimage = ishell_loadimage (PME-> A. m_pishell,
My_image_file );
}

If (PME-> m_pimage ){
Iimage_policy (PME-> m_pimage, drawroutinecb,
(Void *) PME );
}
Else
{
Return efailed; // failed to load Image
}
Return success;
}

// Y callback
Void drawroutinecb (void * puser, iimage * pimage,
Aeeimageinfo * Pi, int nerr)
{
Mydata * PME = (mydata *) puser;

If (! PME |! (PME-> m_pimage)
Return; // image pointer is null

If (nerr = aee_success)
{
// Draw image at 0, 0 coordinates
Iimage_draw (PME-> m_pimage, 0, 0 );

// Update the screen
Idisplay_update (PME-> A. m_pidisplay );

// Free the iimage object
Iimage_release (PME-> m_pimage );
}
}

Note: you cannot release the iimage interface before calling back (through iimage_policy. When the application needs to release the interface before the callback file, it is recommended that the modification indicate that the Boolean flag of the interface should be released in the callback (drawroutinecb in the preceding example.

F. Why can't I see the screen image after I load the image with ishell_loadresimage () and call iimage_draw?
Loading images is asynchronous. When the ishell _ loadresimage () operation returns, the image is not fully loaded and may not be successfully drawn.

When a non-null value is returned, the loading operation is started and the pointer to the image is returned. This does not indicate that the loading operation has been completed. To learn the loading completion time, you should use the iimage_notify () callback. This callback is triggered when the image is successfully loaded and ready to be drawn to the screen. In this case, the user should use iimage_draw () to display the image on the screen.

An example of correctly loading and Drawing Images from files or resources is as follows:

To display images from a resource, follow these steps:
1. Create a bitmap.
2. Add it to the resource editor.
3. Compile the. Bar and. H files in the resource editor.
4. Add the. h file to your project.
5. Use ishell_loadresimage to load the image.
6. If the loading operation returns a non-null value, the loading operation is started and the pointer to the image is returned.
Back. This does not mean that the image loading is completed. To understand the image operation completion time, you need
Use iimage_policy () for callback.
7. When the image is loaded, a callback is triggered.
8. Use iimage _ draw () to display the image during the callback process.
9. Use idisplay_update () to update the screen.
10. Release the iimage pointer.

To display an image in a file, follow these steps:
1. Use ishell_loadimage to load the image from the file.
2. If the loading operation returns a non-null value, the loading operation is started and the pointer to the image is returned.
Back. This does not mean that the image loading is completed. To understand the image operation completion time, you need
Use iimage_policy () for callback.
3. When the image is loaded, a callback is triggered.
4. Use iimage _ draw () to display the image during the callback process.
5. Use idisplay_update () to update the screen.
6. Release the iimage pointer.

Sample Code:
Typedef struct mystruct
{
Aeeapplet;
Iimage * m_pimage;
......
} Mydata;

Enum restype
{
Load_res_from_file,
Load_res_from_res
};

# Define my_res_file "Myres. Bar"
# Define my_image_file "myimg.bmp"

// Load and display a bitmap from a resource and file
Int mydisplayresimage (mydata * PME, restype Rtype)
{
Aeedeviceinfo DM;

If (! PME)
Return efailed;

If (Rtype = load_res_from_res)
{
// Load image from resources
PME-> m_pimage = ishell_loadresimage (
PME-> A. m_pishell,
My_res_file,
Idb_my_color_bitmap );
}
Else // load_res_from_file
{
PME-> m_pimage = ishell_loadimage (PME-> A. m_pishell,
My_image_file );
}

If (PME-> m_pimage ){
Iimage_policy (PME-> m_pimage, drawroutinecb,
(Void *) PME );
}
Else
{
Return efailed; // failed to load Image
}
Return success;
}

// Y callback
Void drawroutinecb (void * puser, iimage * pimage,
Aeeimageinfo * Pi, int nerr)
{
Mydata * PME = (mydata *) puser;

If (! PME |! (PME-> m_pimage)
Return; // image pointer is null

If (nerr = aee_success)
{
// Draw image at 0, 0 coordinates
Iimage_draw (PME-> m_pimage, 0, 0 );

// Update the screen
Idisplay_update (PME-> A. m_pidisplay );

// Free the iimage object
Iimage_release (PME-> m_pimage );
}
}

Note: you cannot release the iimage interface before calling back (through iimage_policy. When the application needs to release the interface before the callback file, it is recommended that the modification indicate that the Boolean flag of the interface should be released in the callback (drawroutinecb in the preceding example.

Does G. Brew Support Animation?
Applicable versions: 1.0, 1.1, 2.0
Brew SDK & reg; version 1.0 supports animation BMP. This is achieved by placing all frames in parallel and specifying the width of each frame using iimage_setparm with a IPARM-CXFRAME mark. See the iimage example in the examples directory.

Brew SDK & reg; version 1.1 adds support for brew compressed image (BCI) animation. The BCI file contains one or more compressed small images, each of which has a duration specified in milliseconds. The duration shows the time that can be displayed before each image is replaced by the next image in the series. You can use the BCI editing tool included in brew SDK & reg; version 1.1 to create a BCI file. For more information, see the "use brew compressed image editing tool" document included in the SDK.

Brew currently does not support animation in PNG or MNG format.

H. Why will all animations become slower after a while?
Applicable versions: 1.0, 1.1, 2.0
Most OEMs use sleep timers. It controls when the device goes to sleep. If no key activity is performed during the period specified by the OEM, the handheld device goes to sleep state. When the device is sleeping, the frame rate will be greatly reduced. Press any key to wake up the device and restore it to the previous frame rate.

In brew 2.0, the application can choose whether to enter sleep state. If the application returns true when it receives the evt_app_no_sleep event, the application will not go to sleep. For example:

Case evt_app_no_sleep:
// Do not sleep
Return true;

I. can I obtain/manipulate the device's palette information?
Applicable versions: 1.0, 1.1, 2.0
No. The palette is hard-coded by the manufacturer and varies with the device.

J. Can I directly modify the display buffer?
Applicable versions: 1.0, 1.1, 2.0
Brew 1.x cannot access these buffers, and the display data is stored in the producer's proprietary format.
From Brew 2.0, if the pixel layout of bitmap is compatible with the brew device-independent bitmap specification, these bitmaps support the idib interface. You can also access the Pixel Buffer through the pbmp members of the idib structure. To determine whether bitmap supports idib and to obtain the idib pointer, you can use the ibitmap_queryinterface function with class ID aeeclsid_dib.

K. Can I perform background rendering?
Applicable versions: 1.0, 1.1, 2.0
You can use idisplay_set/getdestination or igraphics_set/getdestination to perform background rendering. Brew 1.2 and later versions will provide these functions.

1.2 brew SDK & reg; is not provided ;. To use the brew 1.2 feature, you can use the 2.0 SDK to develop brew 1.2-oriented applications. Do not use features of version 1.2 that are not supported in version 2.0. This function list is written in the FAQ documentation. The Brew SDK & reg; 1.2 is installed on the target device, but I cannot find the brew 1.2 SDK. What SDK should I use to develop the BREW application? .

Although the document contains the igraphics_enabledoublebuffer API, it is not supported by any brew version.

L. How to draw a line segment of a specific color?
Applicable versions: 1.0, 1.1, 2.0
Idisplay_drawhline () and idisplay_drawvline () always draw a black line segment. Therefore, set clr_user_line to the desired color, and then call idisplay_drawhline () or idisplay_drawvline () to become invalid.

The two idisplay macros are defined as follows. To draw a line segment with a color other than black, use the code contained in the macro definition and change it to the fill color you want.

# Define idisplay_drawhline (p, X, Y, Len )/
{Aeerect RC; setaeerect (& rc, (x), (y), (LEN), 1); idisplay_fillrect (P), & rc, rgb_black );}

# Define idisplay_drawvline (p, X, Y, Len )/
{Aeerect RC; setaeerect (& rc, (x), (y), 1, (LEN); idisplay_fillrect (P), & rc, rgb_black );}

M. How do I determine the character limits for displaying the application name on the phone?
Applicable versions: 1.0, 1.1, 2.0
Different phones have different display features, so there is no unique answer to this question. You can compare the width and display width of the Application name to determine whether the application name is suitable for phone display.

Use idisplay_measuretext () to determine the pixel width of the Application name string. Use ishell_getdeviceinfo () to determine the pixel width of the screen.

N. How to save the image to the wallpaper directory of the phone?
Applicable versions: 1.0, 1.1, 2.0
Although the current SDK version does not contain the wallpaper API, Some OEMs share the content directory to save images to the wallpaper directory of the local UI.

You can use the following code snippet to create/download images to the shared directory:

// Please note that in order for this code to take effect, the application must
// You have the "access to shared directory" and "file" permissions in the MIF file.
Strcat (filename, aee_shared_dir );
Strcat (filename ,"/");
Strcat (filename, "test.gif ");
Ifilemgr_openfile (m_pifilemgr, filename, _ ofm_create );

The aee_shared_dir is defined by the OEM and mapped to the specific shared directory path of each device. If the OEM supports saving images to the wallpaper directory, the images saved in aee_shared_dir will be displayed in the wallpaper directory of the local UI. To see whether a specific handheld device supports storing wallpaper images and supported image types through a shared directory, see the device data table of the handheld device.

At present, there is no brew API for setting a specific image as a handheld device wallpaper. This must be done through the local UI.

O. Why do I receive a memory error when I use idisplay_bitblt () to draw a bitmap, such as "memheap. c 0696 "?
Applicable versions: 1.0, 1.1, 2.0
Ensure that the memory allocated by convertbmp is released. Check the last Boolean parameter of convertbmp. If this parameter is set to true, the reallocation is completed. You must use sysfree to release the memory.

For example:
Pbmp = convertbmp (pdatabytes, & imageinfo, & bval );
Idisplay_bitblt (pidisplay, xdest, ydest, cxdest, cydest, pbmp,
Xsrc, ysrc, dwropcode );

Idisplay_update (pidisplay );

If (bval) // release only when reallocation is completed
Sysfree (pbmp );

See the convertbmp assistant function descriptions in the API reference documentation. For sample code, see idisplay usage example.

P. Why is the color displayed on the emulator less than expected?
Applicable versions: 1.0, 1.1, 2.0
If the image resolution is low when you display a 16-bit image on the 2.0 simulator, use the device configurator to check the device attributes and set the color depth to 16 bits. If the image resolution is still poor (relative to 8-bit or 16-bit), check whether you have used the iimage_setparm () function to set incorrect parameters for the image to be displayed.

Q. Why are some PNG images not correctly displayed?
Applicable versions: 1.0, 1.1, 2.0
Pay attention to two issues when using PNG images in brew.
1) versions 1.0, 1.1, and 2.0 do not support the alpha channel, but the 3.0 SDK version should support it.
2) brew Only selects the first transparent color in the file to perform transparent processing on PNG. All other colors are displayed. Check the file to make sure that only one transparent color is used when creating the file.

R. Why is the memory size used to create a PNG Image much larger than the actual size of the image?
When the BREW application uses ishell_loadresdata to load PNG images, a large amount of extra space is required to decode the images. For example, a 217-byte PNG Image requires 45,177 bytes of space.

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.