Shape path too large to be rendered into a texture

Source: Internet
Author: User

Shape path too large to be rendered into a texture (747x8294, max = 8192x8192)

 

This problem occurs when the image is displayed. It is analyzed that the size of the loaded path is limited because hardware acceleration is enabled.

 

Scenario:

Select an image from the album or local image and display it in the gridview. You can use similar Image Browsing tools on other pages to view all the displayed images.

When I load all the images on my Image Browsing page and when I load them to large images, oom and bitmap too large to be uploaded into a texture (2448x3264, max = 2048x2048 ).

 

A: OOM

Field: bitmapfactory. decodefile (PATH); When a bitmap is constructed using a URI, the image is too large.

At the beginning, my processing method was as follows:

// Obtain the width and height of the image.
Int width = BM. getwidth ();
Int Height = BM. getheight ();
// Define the width and height of the pre-converted Image
Int newwidth = 400;
Int newheight = 400;
// Calculate the zooming rate. The new size excludes the original size.
Float scalewidth = (float) newwidth)/width;
Float scaleheight = (float) newheight)/height;
// Create a matrix object for image operations
Matrix matrix = new matrix ();
// Scaling the image
Matrix. postscale (scalewidth, scaleheight );
// Create a new image
Bitmap resizedbitmap = bitmap. createbitmap (BM, 0, 0, width, height, matrix, true );
Return bm;

In this way, you need to obtain the width and height of Bitmap in advance. First, you need to construct a bitmap. When constructing a bitmap, oom occurs because the image is too large.

Solution: Use the bitmapfactory. Options class.

Options has a property: Boolean Android. Graphics. bitmapfactory. Options. injustdecodebounds

Options. injustdecodebounds = true;

Bm = bitmapfactory. decodefile (path, options );

/*

If set to true, the decoder will return NULL (no bitmap), but the out... fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.

If this attribute is set to true, the parser will not return bitmap, but null. However, the options. outwidth, options. outheight fields are still set to facilitate the caller to query the width and height of Bitmap. No need to divide memory for the actual pixels of Bitmap.

*/

After obtaining the bitmap width and height, set it to the desired value, and re-construct your bitmap:

Options. outwidth = 400;
Options. outheight = 400;

Options. injustdecodebounds = false;
Bm = bitmapfactory. decodefile (path, options );

**************************************** ***

The above method can get satisfactory images, but the factory still does not save memory during Decode. The following three attributes are used to really save the limited memory of the mobile phone:

Options. inpreferredconfig = bitmap. config. rgb_565; // The default value is argb_8888.

// Use the following two fields together:
Options. inpurgeable = true; // The generated bitmap will get the pixel space. If the system GC is used, it will be cleared. When the pixel is accessed again, if bitmap has decode, it will be automatically decoded again
Options. ininputshareable = true; // bitmap can share a reference input data (inputstream, array, etc)
Options. insamplesize = 4; // decode source 1/4

 

B: bitmap too large to be uploaded into a texture (2448x3264, max = 2048x2048)

Problem: the size of the image is limited by hardware acceleration.

Method: <application Android: hardwareaccelerated = "false"...> disable hardware acceleration (this is a simple and crude method. I admit that I am shameless)

The better solution is similar to the implementation of Google map: divide the image into different blocks and load the required blocks each time. Android provides a method:

Http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html

Shape path too large to be rendered into a texture

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.