在我注意到Bitmap类中有一个压缩方法之前,我已经编写了这个方法。
/**
* Calcuate how much to compress the image
* @param options
* @param reqWidth
* @param reqHeight
* @return
*/
public static int calculateInSampleSize(BitmapFactory.Options options,int reqWidth, int reqHeight) {
final int height = options.outHeight;
这是我的用例:
ByteArray ba; // Some value is assigned here
Bitmap bitmap = BitmapFactory.decodeByteArray(ba, 0, ba.length);
由于ByteArray对象很大,所以在执行以下操作时,将在第二行抛出OutOfMemoryError异常:
BitmapFactory.decodeByteArray(ba, 0, ba.length);
已试过:
ByteArray ba; // Some value is assigned here
BitmapFactory.Options options
在我的android应用程序中,我想把图片上传到服务器上。服务器不接受大小大于2M的图像的问题。但是用户可以选择大于2M的图像。
因此,我想要建立一个代码,使图像小于2M。
我有两种方法:
调整图像尺寸。详情如下:
公共静态位图decodeSampledBitmapFromResource(Resources res,int resId,int reqWidth,int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options o
我有12个像素的照片,它们的大小都不同(1.5MB,2.5MB,3.2MB,4.1MB)等等,它们的分辨率都是相同的4000 x 3000 (像素)。
resizer方法适用于小于3MB的图像,但对于那些大于3MB的图像,它会抛出OutOfMemoryError我不知道什么可以修复它,我的应用程序主要用于调整大图像的大小,这真的让我一无所获。
调整大小的方法是:
public File resizeBitmap(String imPath, int reqSize) {
File fl = null;
try{
// First decode with inJustD
我有活动A、B和C,它们都是setContentView,在这些活动中,XML使用可绘制的a背景。我把我的背景可绘制图像放在可绘制-结核文件夹中。
然而,偶尔,我会在活动B的崩溃报告中得到以下例外
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:56
我有一个加载本地html页面的webview,我需要知道它什么时候加载完成,所以我使用了onPageFinished()函数,该函数会立即触发,但由于某些原因,它在google.co.uk等网站上运行良好。
public class TestwebviewActivity extends Activity {
/** Called when the activity is first created. */
WebView webview = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.
目前,我正在从库中选择一张图片作为设备库中的Uri,然后将其转换为位图,然后根据Uri的大小将其转换为BAOS,然后将其上传到云存储。我想要的是云存储上的每个图像都是200*200像素的图像。 我的代码 File f = new File(resultUri.getPath());
long sizeUri = f.length()/1024;
int quality;
if (sizeUri <= 300)
quality = 30;
else if (sizeUri <= 1000)
我有我的WebView的代码
public static void loadHtml (final Context ctx) {
final WebView webView = new WebView(ctx);
//runnable and 2s delay is set because i load some javascript in onPageFinished
//i omitted it for semplicity
final Handler mHandler = new Handler();
webView.setWebViewCl
我的标签布局有3个标签,只有一个片段,其中包含一个网页视图和一个进度条。我已经为网站创建了3个不同的java文件,其中一个java文件看起来像这样
public class Yahoo extends Fragment {
private WebView webView;
private ProgressBar progressBar1;
private SwipeRefreshLayout mSwipeRefreshLayout1;
public Yahoo() {
// Required empty public construc
当我试图在相机应用程序上拍照并将其上传到服务器端时,我得到了一个NullPointerException,但是有些设备工作正常,还有一些问题。我不知道是什么问题,在一些设备中,它只工作一次,然后就会崩溃。
这些问题是通过使用firebase CrashAnalytics来识别的。
碎片类。
class PhotoUploadFragment : BaseFragment() {
private lateinit var viewModel: SelectOptionViewModel
//define caseId type
private var caseId: