标签: bitmap

Android在App上抛出OutOfMemoryError

我正在制作一个Android应用程序,可以将视频从服务器流式传输到Android移动设备.我有正确的图像流和工作,但15秒后应用程序崩溃.我设法跟踪到Throwing OutOfMemoryError.我尝试回收位图后,我传递一个接口,将其带到线程显示它,但我收到错误"无法重用再循环的位图".我不知道如何解决这个错误,即使斜倚也会修复它.

                    int read_count = 1;
                    long start_time = System.currentTimeMillis();
                    long timeout = 10000;
                    boolean timed_out = false;

                    byte[] data = new byte[size + 1];
                    while (read_count < size && !timed_out)
                    {
                        int len = in.read(data, read_count, size - read_count);
                        read_count += len;
                        timed_out = (System.currentTimeMillis() - start_time) >= timeout;
                    }
                    data[0] = (byte)0x89;

                    if (read_count == size)
                    {
                        final boolean is_left = (side == 0);
                        final byte[] tmp = data;
                        Bitmap Image_data = null;
                        System.out.println(tmp.length);
                        if (Listener != null) …
Run Code Online (Sandbox Code Playgroud)

sockets android bitmap android-memory google-cardboard

3
推荐指数
1
解决办法
4513
查看次数

C#调整位图大小而不更改Pixelformat

我有一个BGR格式和分辨率1920*1200的位图,并希望在不更改pixelformat的情况下缩放它.

private Bitmap rescale(Size size, Bitmap origin)
{
    Bitmap scaled = new Bitmap(origin, size);
    return scaled;
}
Run Code Online (Sandbox Code Playgroud)

问题是,缩放结果是一个RGBA位图(所有alphas都在255),这对我来说不仅无用,而且后来我在不同的图像上做AbsDiff(来自EMGU)然后, alpha值总是为零.有没有办法在缩放时不改变pixelformat或者在没有alpha值的情况下进行AbsDiff?因为像这样,当我稍后加载图像时,它是不可见的..

c# bitmap emgucv

3
推荐指数
2
解决办法
2319
查看次数

将图像文件从相机压缩到一定大小

我正在尝试压缩我保存在文件中的图像.我正在尝试将文件压缩为1MB.我尝试了一些方法,但它通常会产生一个OutofMemoryError.然后我尝试使用此解决方案,但它使位图空白.

如何将位图从10mb图像从相机压缩到300kb beforw设置到android中的imageview

这是我的代码:

    System.gc();
    getActivity().getContentResolver().notifyChange(mImageTempUri, null);
    Bitmap bitmap;
    bitmap = BitmapFactory.decodeFile(mImageDirectory + mImageName, options);
    if(bitmap == null){
    howRequestFailedErrorMessage("Gambar gagal di-upload");
    return;

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();   


    bitmap.compress(Bitmap.CompressFormat.JPEG, 25, bytes);
    File f = new File(mImageDirectory + mImageName);
    if(f.exists()){
        f.delete();
    }
    FileOutputStream fo;

    try {
        fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
        fo.flush();
        fo.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    bitmap.recycle();
Run Code Online (Sandbox Code Playgroud)

android memory-management bitmap android-bitmap

3
推荐指数
1
解决办法
5883
查看次数

Android BitmapFactory.decodeResource需要太多内存

我有关于从资源加载Bitmap的问题.我的代码:

public void onClick(View view) {
    if (mainButton == view) {
        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.test);
    }
}
Run Code Online (Sandbox Code Playgroud)

test.jpg图像分辨率为3288 x 4936px.它是jpeg(未压缩时为3,9MB/48,7MB).虽然此功能有效(在我的Nexus 7 2013设备上),但会发生以下异常:

java.lang.OutOfMemoryError: Failed to allocate a 259673100 byte allocation with 5222644 free bytes and 184MB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
        at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:467)
        at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:497)
        at pl.jaskol.androidtest.MainActivity.onClick(MainActivity.java:50)
        at android.view.View.performClick(View.java:4756)
        at android.view.View$PerformClick.run(View.java:19749)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Run Code Online (Sandbox Code Playgroud)

为什么应用程序尝试分配多达248MB?我在Qt for Android中编写了类似的应用程序,在资源中使用相同的图像并且工作正常.

编辑: …

java memory android image bitmap

3
推荐指数
1
解决办法
6561
查看次数

原始像素数组到灰度BitmapImage

我有一组原始像素数据.我想将其转换为8bpp Bitmap.

public static Bitmap ByteToGrayBitmap(byte[] rawBytes, int width, int height) 
{ 
    Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
    BitmapData  bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height),
                                    ImageLockMode.WriteOnly, bitmap.PixelFormat);

    Marshal.Copy(rawBytes, 0, bitmapData .Scan0, rawBytes.Length);
    bitmap.UnlockBits(bitmapData);

    return bitmap;
}
Run Code Online (Sandbox Code Playgroud)

位图看起来像彩色图像而不是灰度.

c# bitmap

3
推荐指数
2
解决办法
1546
查看次数

EMGU CV视频摄像师无法制作视频

我试图使用Emgu CV VideoWriter捕获视频,但它显示:

无法创建VideoWriter.确保安装了特定的编解码器

我该如何处理?
这就是我的代码:

Bitmap back = new Bitmap("jpg image path");
Image<Bgr, Byte> bg;
bg = new Image(Bgr, byte)(back);
vw = new VideoWriter("c://work//test1.mp4",CvInvoke.CV_FOURCC('M','S','V','C'), 17, 640, 480, true);
Run Code Online (Sandbox Code Playgroud)

它适用于.avi扩展,但是只有几秒钟的大小相当大,所以我想更多地压缩它.请建议代码/库的任何变通方法或更改.

c# opencv bitmap image-compression emgucv

3
推荐指数
1
解决办法
6774
查看次数

如何在Android的视频中添加文字?

在我的应用中,我录制了一个视频,我想在该视频的右下角覆盖我公司的网址。我使用MediaRecorder录制视频,但是录制没有问题,但是在视频中添加文字并没有成功。我搜索并找到了一些库,例如FFmpeg和JavaCV,这些库可以让用户在视频上覆盖文本,但是我不知道是否有任何方法可以在Android中使用它们。之后,找到OnPreviewFrame,它返回camerapreivew的每一帧。我想在用户触摸录制按钮后获取所有帧,并使用画布在每个帧上绘制文本,然后将所有这些帧保存在一起,直到停止录制视频,并且视频持续时间固定为15秒。这是一个好的解决方案吗?如果是,应该如何实现OnPreviewFrame函数?我知道怎么画画布,但是我不知道

video android ffmpeg canvas bitmap

3
推荐指数
1
解决办法
4683
查看次数

使用AssetManager时,位图字体颠倒

今天我开始使用AssetManagerfrom libGDX来加载我的资产.在此之前我已经在一个单独的类中加载了所有内容,但我没有使用AssetManager.
我目前如何加载位图字体:

manager.load("font/good_neighbors_unity.fnt", BitmapFont.class);
[...]
bFont = manager.get("font/good_neighbors_unity.fnt", BitmapFont.class);
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我使用Asset Manager加载时,我使用的位图字体是颠倒的.这是因为在我的正交相机中,y指向下方.在Bitmap Font构造函数中有一个布尔值来翻转字体并避免此问题.但是当我加载它时似乎没有这样的选项AssetManager.可能有一个相对简单的解决方案,但我找不到任何允许我翻转字体的方法.有没有一个选项允许我在使用时翻转位图字体AssetManager?

java fonts bitmap libgdx

3
推荐指数
1
解决办法
234
查看次数

如何将redis位图(二进制字符串)转换为前导零的二进制数?

我使用redis位图来记录一年中的用户操作,如果用户在一年中的第一天登录,我会将密钥的第一位设置为1. redis值如下:

key:user.18.action(18是用户id)
值:(位图)000100000000000000000000 ...(约365位长)

但当我试图获得价值时,GET user.18.action返回"\x10".

在PHP中,如何将这些字符串转换为该字符串000100000000000000000000...?

实际上,我使用下面的代码来实现它,但这样可以吗?并且有更好的解决方案吗?

$bitmap = $this->redis->get('user.18.action');
$binstrlen = strlen($bitmap);
$hex = bin2hex($bitmap);
$str = str_baseconvert($hex, 16, 2);
var_dump(str_pad($str, $binstrlen * 8, '0', STR_PAD_LEFT));

function str_baseconvert($str, $frombase=10, $tobase=36) { 
    $str = trim($str); 
    if (intval($frombase) != 10) { 
        $len = strlen($str); 
        $q = 0; 
        for ($i=0; $i<$len; $i++) { 
            $r = base_convert($str[$i], $frombase, 10); 
            $q = bcadd(bcmul($q, $frombase), $r); 
        } 
    } 
    else $q = $str; 

    if (intval($tobase) != …
Run Code Online (Sandbox Code Playgroud)

php bitmap bitset redis

3
推荐指数
1
解决办法
718
查看次数

如何创建圆形facebook个人资料图片

我无法使用此库将我的一个图像动态地制作成一个圆圈.这是我的尝试:

private void drawerSetup() {
    Profile profile = Profile.getCurrentProfile();
    ProfilePictureView profilePictureView = (ProfilePictureView) findViewById(R.id.profile_image);
    CircularImageView circularProfilePicture = (CircularImageView)    findViewById(R.id.profile_image_circle);
    if(profilePictureView != null) {
        profilePictureView.setProfileId(profile.getId());
        ImageView imageView = ((ImageView)profilePictureView.getChildAt(0));
        Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
        circularProfilePicture.setImageBitmap(bitmap);
    }
}
Run Code Online (Sandbox Code Playgroud)

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    xmlns:facebook="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/tools"
    android:background="@drawable/side_nav_bar"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:orientation="vertical"
    android:gravity="bottom"
    app:showIn="@layout/activity_news_feed">

<com.facebook.login.widget.ProfilePictureView
    android:id="@+id/profile_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    facebook:com_facebook_preset_size="normal"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:paddingBottom="8dp"
    android:layout_centerInParent="true" />

<com.mikhaellopez.circularimageview.CircularImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    app:border_color="#EEEEEE"
    app:border_width="2dp"
    app:shadow="true"
    app:shadow_radius="10"
    android:id="@+id/profile_image_circle"
    app:shadow_color="#000000"
    android:layout_alignBottom="@+id/profile_image"
    android:layout_toLeftOf="@+id/profile_image"
    android:layout_toStartOf="@+id/profile_image" />
Run Code Online (Sandbox Code Playgroud)

我知道profilePictureView当我打电话给 …

android facebook bitmap imageview profile-picture

3
推荐指数
1
解决办法
7002
查看次数