相关疑难解决方法(0)

如果.NET中的MemoryStream未关闭,是否会创建内存泄漏?

我有以下代码:

MemoryStream foo(){
    MemoryStream ms = new MemoryStream();
    // write stuff to ms
    return ms;
}

void bar(){
    MemoryStream ms2 = foo();
    // do stuff with ms2
    return;
}
Run Code Online (Sandbox Code Playgroud)

我分配的MemoryStream是否有可能以后不能被处理掉?

我有一个同行评审坚持我手动关闭它,我找不到信息来判断他是否有一个有效点.

.net c# memory-leaks memorystream

108
推荐指数
6
解决办法
7万
查看次数

Android:Bitmap recycle()如何工作?

假设我在一个位图对象中加载了一个图像

Bitmap myBitmap = BitmapFactory.decodeFile(myFile);
Run Code Online (Sandbox Code Playgroud)

现在,如果我加载另一个位图,会发生什么

myBitmap = BitmapFactory.decodeFile(myFile2);
Run Code Online (Sandbox Code Playgroud)

第一个myBitmap会发生什么?它是否收集垃圾或者我必须在加载另一个位图之前手动垃圾收集它,例如. myBitmap.recycle()

此外,是否有更好的方法来加载大图像并在途中回收时一个接一个地显示它们?

android bitmap

86
推荐指数
5
解决办法
9万
查看次数

如何在不改变位图大小的情况下进行位图压缩?

我用这种方法来压缩图像

if(bitmapObject.compress(Bitmap.CompressFormat.PNG, 100, fOut))
{
    ... 
}
Run Code Online (Sandbox Code Playgroud)

但是我得到的图像在压缩动作之前的尺寸要小得多(在尺寸上).

我的应用程序需要通过网络发送压缩图像 - 所以我想发送尽可能少的数据...但我必须保持图像的原始大小.

有没有其他方法来保持原始位图维度与一些压缩?

android

52
推荐指数
3
解决办法
16万
查看次数

在解码位图时捕获OutOfMemoryError

即使您已经尝试了一些减少内存使用的方法,捕获OutOfMemoryError是一个好习惯吗?或者我们应该不抓住异常?哪一个更好的做法?

try {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    bitmap = BitmapFactory.decodeFile(file, options);
} catch (OutOfMemoryError e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

谢谢

android bitmap out-of-memory

23
推荐指数
2
解决办法
1万
查看次数

Android - 缩放和压缩位图

我正在开发一款Android应用程序,它具有摄像头捕捉和照片上传功能.如果设备具有高分辨率相机,则捕获的图像尺寸将非常大(1~3MB或更多).
由于应用程序需要将此图像上传到服务器,因此我需要在上传之前压缩图像.例如,如果相机捕获了1920x1080全分辨率照片,则理想输出是保持图像的16:9比例,将其压缩为640x360图像以降低某些图像质量并使其以字节为单位缩小.

这是我的代码(从谷歌引用):

/**
 * this class provide methods that can help compress the image size.
 *
 */
public class ImageCompressHelper {

/**
 * 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) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width …
Run Code Online (Sandbox Code Playgroud)

java android image bitmap image-processing

7
推荐指数
1
解决办法
4万
查看次数