在 Android 应用中加载位图比较复杂,原因有很多种:
- 位图很容易就会耗尽应用的内存预算。例如,Pixel 手机上的相机拍摄的照片最大可达 4048x3036 像素(1,200 万像素)。如果使用的位图配置为
ARGB_8888
,这是 Android 2.3(API 级别 9)及更高版本的默认设置,将单张照片加载到内存大约需要 48 MB 内存(4048*3036*4 字节)。如此庞大的内存需求可能会立即耗尽该应用的所有可用内存。 - 在界面线程中加载位图会降低应用的性能,导致响应速度变慢,甚至会导致系统显示 ANR 消息。因此,在使用位图时,必须正确地管理线程处理。
- 如果您的应用将多个位图加载到内存中,您需要娴熟地管理内存和磁盘缓存。否则,应用界面的响应速度和流畅性可能会受到影响。
在大多数情况下,我们建议您使用 Glide 库获取、解码和显示应用中的位图。在处理这些任务以及与位图和 Android 上的其他图片相关的其他任务时,Glide 会将大部分的复杂工作抽象出来。如需了解如何使用和下载 Glide,请访问 GitHub 上的 Glilt 代码库。
您也可以选择直接使用 Android 框架中内置的较低级 API。如需详细了解如何执行此操作,请参阅高效加载较大位图、缓存位图和管理位图内存。
更多资源
फ़रवरी 2025
Android 16 का बीटा वर्शन 2 आ गया है: इसमें प्रो कैमरे की सुविधाएं शामिल हैं. जैसे, हाइब्रिड ऑटो-एक्सपोज़र और रंग में सटीक बदलाव, UltraHDR इमेज के अपडेट, नए एजीएसएल इफ़ेक्ट वगैरह. पक्का करें कि आपने व्यवहार में हुए हाल ही के बदलावों के हिसाब से जांच की हो.
जनवरी 2025
हमने साल 2024 में, Google Play और Android ऐप्लिकेशन नेटवर्क को कैसे सुरक्षित रखा. Google Play को सुरक्षित रखना हमारी सबसे बड़ी प्राथमिकता है. इसलिए, हम अपने प्लैटफ़ॉर्म को सुरक्षित रखने के लिए, नए तरीके ढूंढते रहते हैं.
दिसंबर 2024
साल 2024 खत्म होने वाला है. हमारी पार्टनरशिप के लिए आपका धन्यवाद. Google Play की पूरी टीम की ओर से, हमारी कम्यूनिटी का अहम हिस्सा बने रहने के लिए धन्यवाद.
नवंबर 2024
Android 16 का पहला डेवलपर प्रीव्यू: Android 16 का पहला डेवलपर प्रीव्यू 1 आ गया है. अब इसे अपने ऐप्लिकेशन के साथ टेस्ट किया जा सकता है.
अक्टूबर 2024
Google Play पर अपने कारोबार को आगे बढ़ाने के लिए नए अपडेट: अपने ऐप्लिकेशन और गेम के लिए हमारे नए अपडेट की मदद से, दर्शकों की संख्या बढ़ाएं, यूज़र ऐक्टिविटी बढ़ाएं, और आय को ऑप्टिमाइज़ करें.
अगस्त 2024
#TheAndroidShow पर Google का बनाया हुआ: इस महीने के Made by Google इवेंट की मदद से, उपहार में मिले नए Pixel फ़ोन और स्मार्टवॉच का आनंद लें. इसके बाद, आपको यह भी पता चलेगा कि Wear OS 5, फ़ोल्ड किए जा सकने वाले डिवाइसों, और अन्य डिवाइसों के लिए ऐप्लिकेशन कैसे बनाते हैं.
जुलाई 2024
पेश है कलेक्शन, आपके कॉन्टेंट को डिवाइस पर ही देखने की सुविधा: कलेक्शन, लोगों को उनके इंस्टॉल किए गए ऐप्लिकेशन से सबसे अच्छा और सबसे काम का कॉन्टेंट उपलब्ध कराते हैं. ये कॉन्टेंट खास तौर पर इन इंटेंट के हिसाब से बनाए जाते हैं, जैसे कि 'देखें' या 'सुनें'.
September 2024
Android 15 released to AOSP: now released to the Android Open Source Project (AOSP), Android 15 continues our focus on a private and secure platform that helps improve your productivity.
June 2024
Top updates from Google Play at I/O: discover new ways to reach the right audiences with the right content, boost your revenue with more payment options, and build safer app experiences.
May 2024
Google Play at I/O 2024: check out the Google Play keynote to discover the latest helpful products and features.
April 2024
Google I/O program details are now live: Get a sneak peek at this year’s 150+ sessions and learning content covering mobile, web, multi-platform development, and more.
March 2024
Play is back at Google I/O: Join us online on May 14 to discover, innovate, and unlock new possibilities with Google's latest developer tools.
February 2024
The first developer preview of Android 15 is here: Android 15 makes it easier to improve your productivity with enhancements to performance, privacy, security, and user expression.
January 2024
Google for Games Developer Summit returns March 12: hear from teams across Google on the latest products and best practices to drive business growth across the entire game lifecycle.
December 2023
Since joining Google Play at the start of this year, it's been my privilege to support the hard work and creativity of our incredible community of people building apps and games.
November 2023
5 must-know Google Play updates: discover new ways to grow and engage your audience, create best-in-class experiences, and monetize your apps and games on Google Play.
October 2023
Learn how we're supporting app quality on Google Play: we're rolling out updates across generative AI, photo and video permissions, and more - all designed to protect users. Learn more about the changes we're making to keep Google Play safe for developers and users.
September 2023
Notes from Google Play: Keeping our platform safe - people are increasingly concerned about the privacy and security of the titles they download. Therefore, it’s more important than ever to grow user trust with high-quality app experiences built on a secure foundation.
August 2023
Get help from Google AI when drafting your custom store listing - take our new Google Play Academy course to learn how an experimental Google AI feature can help you draft custom store listings.
July 2023
A new Play Store for large screens - this new version helps users more easily find high-quality apps and games that are optimized for their tablets, foldables, and Chromebooks.
June 2023
New price experiments feature now available in Play Console - price your in-app products with confidence with our new price experiments feature. In just minutes, set up a test to optimize for local purchasing power across markets.
May 2023
Google Play at I/O 2023 - over the past year, our teams have been laser-focused on building exciting new features and making major changes to help your business thrive on Google Play.
April 2023
Giving users control over account data - apps that allow account creation will soon need to allow users to initiate account and data deletion from within the app and online. Showcase your apps' privacy and security practices in your Data safety section in a simple and easy-to-understand way.
March 2023
Let’s go, it’s Google I/O - join us online on May 10. Learn about the latest Google Play updates at Google I/O and what we’re doing to help you work smarter, ship faster, and stay inspired.