安卓图片优化之Bitmap优化(一)

Android开发之网络图片查看方法BitmapFactory.decodeStream()学习01 Android实现网络图片的查看有好几种方法,但这本身是一种很耗时的操作,可以通过直接获取和操作线程的方法,自己学习使用了BitmapFactory.decodeStream()在代码中自己写了注释,大致分为以下几步: ①设置URL对象和连接  ②设置一下在连接和读取过程中的超时时间防止长时间无响应的等待  ③连接成功后根据数据流创建一个Bitmap的位图对象,最后返回Bitmap类型   阅读详情

原文链接:http://www.cnblogs.com/whoislcj/p/5547758.html


Bitmap:

     Bitmap是Android系统中的图像处理的最重要类之一。用它可以获取图像文件信息,进行图像剪切、旋转、缩放等操作,并可以指定格式保存图像文件。

 重要函数

  •  public void recycle() // 回收位图占用的内存空间,把位图标记为Dead

  •  public final boolean isRecycled() //判断位图内存是否已释放  

  •  public final int getWidth()//获取位图的宽度 

  •  public final int getHeight()//获取位图的高度

  •  public final boolean isMutable()//图片是否可修改 

  •  public int getScaledWidth(Canvas canvas)//获取指定密度转换后的图像的宽度 

  •  public int getScaledHeight(Canvas canvas)//获取指定密度转换后的图像的高度 

  • public boolean compress(CompressFormat format, int quality, OutputStream stream)//按指定的图片格式以及画质,将图片转换为输出流。 

    format:Bitmap.CompressFormat.PNG或Bitmap.CompressFormat.JPEG 

    quality:画质,0-100.0表示最低画质压缩,100以最高画质压缩。对于PNG等无损格式的图片,会忽略此项设置。

  • public static Bitmap createBitmap(Bitmap src) //以src为原图生成不可变得新图像 

  • public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)//以src为原图,创建新的图像,指定新图像的高宽以及是否可变。 

  • public static Bitmap createBitmap(int width, int height, Config config)——创建指定格式、大小的位图 

  • public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height)以source为原图,创建新的图片,指定起始坐标以及新图像的高宽。

BitmapFactory工厂类:

    Option 参数类:
  • public boolean inJustDecodeBounds//如果设置为true,不获取图片,不分配内存,但会返回图片的高度宽度信息。

  • public int inSampleSize//图片缩放的倍数

  • public int outWidth//获取图片的宽度值

  • public int outHeight//获取图片的高度值 

  • public int inDensity//用于位图的像素压缩比 

  • public int inTargetDensity//用于目标位图的像素压缩比(要生成的位图) 

  • public byte[] inTempStorage //创建临时文件,将图片存储

  • public boolean inScaled//设置为true时进行图片压缩,从inDensity到inTargetDensity

  • public boolean inDither //如果为true,解码器尝试抖动解码

  • public Bitmap.Config inPreferredConfig //设置解码器

  • public String outMimeType //设置解码图像

  • public boolean inPurgeable//当存储Pixel的内存空间在系统内存不足时是否可以被回收

  • public boolean inInputShareable //inPurgeable为true情况下才生效,是否可以共享一个InputStream

  • public boolean inPreferQualityOverSpeed  //为true则优先保证Bitmap质量其次是解码速度

  • public boolean inMutable //配置Bitmap是否可以更改,比如:在Bitmap上隔几个像素加一条线段

  • public int inScreenDensity //当前屏幕的像素密度

  工厂方法:
  • public static Bitmap decodeFile(String pathName, Options opts) //从文件读取图片 

  • public static Bitmap decodeFile(String pathName)

  • public static Bitmap decodeStream(InputStream is) //从输入流读取图片

  • public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts)

  • public static Bitmap decodeResource(Resources res, int id) //从资源文件读取图片

  • public static Bitmap decodeResource(Resources res, int id, Options opts) 

  • public static Bitmap decodeByteArray(byte[] data, int offset, int length) //从数组读取图片

  • public static Bitmap decodeByteArray(byte[] data, int offset, int length, Options opts)

  • public static Bitmap decodeFileDescriptor(FileDescriptor fd)//从文件读取文件 与decodeFile不同的是这个直接调用JNI函数进行读取 效率比较高

  • public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts)

  Bitmap.Config inPreferredConfig :

     枚举变量 (位图位数越高代表其可以存储的颜色信息越多,图像越逼真,占用内存越大)

  • public static final Bitmap.Config ALPHA_8 //代表8位Alpha位图        每个像素占用1byte内存
  • public static final Bitmap.Config ARGB_4444 //代表16位ARGB位图  每个像素占用2byte内存
  • public static final Bitmap.Config ARGB_8888 //代表32位ARGB位图  每个像素占用4byte内存
  • public static final Bitmap.Config RGB_565 //代表8位RGB位图          每个像素占用2byte内存
      Android中一张图片(BitMap)占用的内存主要和以下几个因数有关:图片长度,图片宽度,单位像素占用的字节数。一张图片(BitMap)占用的内存=图片长度*图片宽度*单位像素占用的字节数
图片读取实例:
   1.)从文件读取方式一
复制代码
   /**
     * 获取缩放后的本地图片
     *
     * @param filePath 文件路径
     * @param width    宽
     * @param height   高
     * @return
     */
    public static Bitmap readBitmapFromFile(String filePath, int width, int height) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, options);
        float srcWidth = options.outWidth;
        float srcHeight = options.outHeight;
        int inSampleSize = 1;

        if (srcHeight > height || srcWidth > width) {
            if (srcWidth > srcHeight) {
                inSampleSize = Math.round(srcHeight / height);
            } else {
                inSampleSize = Math.round(srcWidth / width);
            }
        }

        options.inJustDecodeBounds = false;
        options.inSampleSize = inSampleSize;

        return BitmapFactory.decodeFile(filePath, options);
    }
复制代码
 2.)从文件读取方式二 效率高于方式一
复制代码
/**
     * 获取缩放后的本地图片
     *
     * @param filePath 文件路径
     * @param width    宽
     * @param height   高
     * @return
     */
    public static Bitmap readBitmapFromFileDescriptor(String filePath, int width, int height) {
        try {
            FileInputStream fis = new FileInputStream(filePath);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFileDescriptor(fis.getFD(), null, options);
            float srcWidth = options.outWidth;
            float srcHeight = options.outHeight;
            int inSampleSize = 1;

            if (srcHeight > height || srcWidth > width) {
                if (srcWidth > srcHeight) {
                    inSampleSize = Math.round(srcHeight / height);
                } else {
                    inSampleSize = Math.round(srcWidth / width);
                }
            }

            options.inJustDecodeBounds = false;
            options.inSampleSize = inSampleSize;

            return BitmapFactory.decodeFileDescriptor(fis.getFD(), null, options);
        } catch (Exception ex) {
        }
        return null;
    }
复制代码

测试同样生成10张图片两种方式耗时比较 cpu使用以及内存占用两者相差无几 第二种方式效率高一点 所以建议优先采用第二种方式

复制代码
      start = System.currentTimeMillis();
        for (int i = 0; i < testMaxCount; i++) {
            BitmapUtils.readBitmapFromFile(filePath, 400, 400);
        }
        end = System.currentTimeMillis();
        Log.e(TAG, "BitmapFactory decodeFile--time-->" + (end - start));

        start = System.currentTimeMillis();
        for (int i = 0; i < testMaxCount; i++) {
           BitmapUtils.readBitmapFromFileDescriptor(filePath, 400, 400);
        }
        end = System.currentTimeMillis();
        Log.e(TAG, "BitmapFactory decodeFileDescriptor--time-->" + (end - start));
复制代码

3.)从输入流中读取文件
复制代码
  /**
     * 获取缩放后的本地图片
     *
     * @param ins    输入流
     * @param width  宽
     * @param height 高
     * @return
     */
    public static Bitmap readBitmapFromInputStream(InputStream ins, int width, int height) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(ins, null, options);
        float srcWidth = options.outWidth;
        float srcHeight = options.outHeight;
        int inSampleSize = 1;

        if (srcHeight > height || srcWidth > width) {
            if (srcWidth > srcHeight) {
                inSampleSize = Math.round(srcHeight / height);
            } else {
                inSampleSize = Math.round(srcWidth / width);
            }
        }

        options.inJustDecodeBounds = false;
        options.inSampleSize = inSampleSize;

        return BitmapFactory.decodeStream(ins, null, options);
    }
复制代码
4.)从资源文件中读取文件 
复制代码
    public static Bitmap readBitmapFromResource(Resources resources, int resourcesId, int width, int height) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(resources, resourcesId, options);
        float srcWidth = options.outWidth;
        float srcHeight = options.outHeight;
        int inSampleSize = 1;

        if (srcHeight > height || srcWidth > width) {
            if (srcWidth > srcHeight) {
                inSampleSize = Math.round(srcHeight / height);
            } else {
                inSampleSize = Math.round(srcWidth / width);
            }
        }

        options.inJustDecodeBounds = false;
        options.inSampleSize = inSampleSize;

        return BitmapFactory.decodeResource(resources, resourcesId, options);
    }
复制代码

 此种方式相当的耗费内存 建议采用decodeStream代替decodeResource 可以如下形式

复制代码
    public static Bitmap readBitmapFromResource(Resources resources, int resourcesId, int width, int height) {
        InputStream ins = resources.openRawResource(resourcesId);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(ins, null, options);
        float srcWidth = options.outWidth;
        float srcHeight = options.outHeight;
        int inSampleSize = 1;

        if (srcHeight > height || srcWidth > width) {
            if (srcWidth > srcHeight) {
                inSampleSize = Math.round(srcHeight / height);
            } else {
                inSampleSize = Math.round(srcWidth / width);
            }
        }

        options.inJustDecodeBounds = false;
        options.inSampleSize = inSampleSize;

        return BitmapFactory.decodeStream(ins, null, options);
    }
复制代码

decodeStream、decodeResource占用内存对比:

复制代码
 start = System.currentTimeMillis();
        for (int i = 0; i < testMaxCount; i++) {
            BitmapUtils.readBitmapFromResource(getResources(), R.mipmap.ic_app_center_banner, 400, 400);
            Log.e(TAG, "BitmapFactory decodeResource--num-->" + i);
        }
        end = System.currentTimeMillis();
        Log.e(TAG, "BitmapFactory decodeResource--time-->" + (end - start));

        start = System.currentTimeMillis();
        for (int i = 0; i < testMaxCount; i++) {
            BitmapUtils.readBitmapFromResource1(getResources(), R.mipmap.ic_app_center_banner, 400, 400);
            Log.e(TAG, "BitmapFactory decodeStream--num-->" + i);
        }
        end = System.currentTimeMillis();
        Log.e(TAG, "BitmapFactory decodeStream--time-->" + (end - start));
复制代码

BitmapFactory.decodeResource 加载的图片可能会经过缩放,该缩放目前是放在 java 层做的,效率比较低,而且需要消耗 java 层的内存。因此,如果大量使用该接口加载图片,容易导致OOM错误

BitmapFactory.decodeStream 不会对所加载的图片进行缩放,相比之下占用内存少,效率更高。

这两个接口各有用处,如果对性能要求较高,则应该使用 decodeStream;如果对性能要求不高,且需要 Android 自带的图片自适应缩放功能,则可以使用 decodeResource。

5. )从二进制数据读取图片
复制代码
public static Bitmap readBitmapFromByteArray(byte[] data, int width, int height) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(data, 0, data.length, options);
        float srcWidth = options.outWidth;
        float srcHeight = options.outHeight;
        int inSampleSize = 1;

        if (srcHeight > height || srcWidth > width) {
            if (srcWidth > srcHeight) {
                inSampleSize = Math.round(srcHeight / height);
            } else {
                inSampleSize = Math.round(srcWidth / width);
            }
        }

        options.inJustDecodeBounds = false;
        options.inSampleSize = inSampleSize;

        return BitmapFactory.decodeByteArray(data, 0, data.length, options);
    }
复制代码
6.)从assets文件读取图片
复制代码
  /**
     * 获取缩放后的本地图片
     *
     * @param filePath 文件路径
     * @return
     */
    public static Bitmap readBitmapFromAssetsFile(Context context, String filePath) {
        Bitmap image = null;
        AssetManager am = context.getResources().getAssets();
        try {
            InputStream is = am.open(filePath);
            image = BitmapFactory.decodeStream(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return image;
    }
复制代码
图片保存文件:
复制代码
    public static void writeBitmapToFile(String filePath, Bitmap b, int quality) {
        try {
            File desFile = new File(filePath);
            FileOutputStream fos = new FileOutputStream(desFile);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            b.compress(Bitmap.CompressFormat.JPEG, quality, bos);
            bos.flush();
            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
复制代码
图片压缩:
复制代码
    private static Bitmap compressImage(Bitmap image) {
        if (image == null) {
            return null;
        }
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();
            image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            byte[] bytes = baos.toByteArray();
            ByteArrayInputStream isBm = new ByteArrayInputStream(bytes);
            Bitmap bitmap = BitmapFactory.decodeStream(isBm);
            return bitmap;
        } catch (OutOfMemoryError e) {
        } finally {
            try {
                if (baos != null) {
                    baos.close();
                }
            } catch (IOException e) {
            }
        }
        return null;
    }
复制代码
图片缩放:
复制代码
    /**
     * 根据scale生成一张图片
     *
     * @param bitmap
     * @param scale  等比缩放值
     * @return
     */
    public static Bitmap bitmapScale(Bitmap bitmap, float scale) {
        Matrix matrix = new Matrix();
        matrix.postScale(scale, scale); // 长和宽放大缩小的比例
        Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        return resizeBmp;
    }
复制代码
获取图片旋转角度:
复制代码
 /**
     * 读取照片exif信息中的旋转角度
     *
     * @param path 照片路径
     * @return角度
     */
    private static int readPictureDegree(String path) {
        if (TextUtils.isEmpty(path)) {
            return 0;
        }
        int degree = 0;
        try {
            ExifInterface exifInterface = new ExifInterface(path);
            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    degree = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    degree = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    degree = 270;
                    break;
            }
        } catch (Exception e) {
        }
        return degree;
    }
复制代码
图片旋转角度:
复制代码
    private static Bitmap rotateBitmap(Bitmap b, float rotateDegree) {
        if (b == null) {
            return null;
        }
        Matrix matrix = new Matrix();
        matrix.postRotate(rotateDegree);
        Bitmap rotaBitmap = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
        return rotaBitmap;
    }
复制代码
图片转二进制:
    public byte[] bitmap2Bytes(Bitmap bm) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return baos.toByteArray();
    }
Bitmap转Drawable
  public static Drawable bitmapToDrawable(Resources resources, Bitmap bm) {
        Drawable drawable = new BitmapDrawable(resources, bm);
        return drawable;
    }
Drawable转Bitmap
复制代码
    public static Bitmap drawableToBitmap(Drawable drawable) {
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    }
复制代码
Drawable、Bitmap占用内存探讨

之前一直使用过Afinal 和Xutils 熟悉这两框架的都知道,两者出自同一人,Xutils是Afina的升级版,AFinal中的图片内存缓存使用的是Bitmap 而后来为何Xutils将内存缓存的对象改成了Drawable了呢?我们一探究竟

写个测试程序:

复制代码
        List<Bitmap> bitmaps = new ArrayList<>();
        start = System.currentTimeMillis();
        for (int i = 0; i < testMaxCount; i++) {
            Bitmap bitmap = BitmapUtils.readBitMap(this, R.mipmap.ic_app_center_banner);
            bitmaps.add(bitmap);
            Log.e(TAG, "BitmapFactory Bitmap--num-->" + i);
        }
        end = System.currentTimeMillis();
        Log.e(TAG, "BitmapFactory Bitmap--time-->" + (end - start));

        List<Drawable> drawables = new ArrayList<>();
        
        start = System.currentTimeMillis();
        for (int i = 0; i < testMaxCount; i++) {
            Drawable drawable = getResources().getDrawable(R.mipmap.ic_app_center_banner);
            drawables.add(drawable);
            Log.e(TAG, "BitmapFactory Drawable--num-->" + i);
        }
        end = System.currentTimeMillis();
        Log.e(TAG, "BitmapFactory Drawable--time-->" + (end - start));
复制代码

测试数据1000 同一张图片

 Bitmap 直接70条数据的时候挂掉

Drawable 轻松1000条数据通过

从测试说明Drawable 相对Bitmap有很大的内存占用优势。这也是为啥现在主流的图片缓存框架内存缓存那一层采用Drawable作为缓存对象的原因。

小结:

    图片处理就暂时学习到这里,以后再做补充。




Android13 BitmapFactory decodeStream流程分析 BitmapFactory的decodeStream()方法用于从输入流中解码图像,并返回一个Bitmap对象。 阅读详情

相关推荐

[Android] Android开发优化之——对Bitmap的内存优化

在Android应用里,最耗费内存的就是图片资源。而且在Android系统中,读取位图Bitmap时,分给虚拟机中的图片的堆栈大小只有8M,如果超出了,就会出现OutOfMemory异常。所以,对于图片的内存优化,是Android应用开发中比较重要的内容。 1) 要及时回收Bitmap的内存Bitmap类有一个方法recycle(),从方法名可以看出意思是回收。这里就有疑问了,Android系统有

::: 移动互联网时代开发者 ::: 4万+

android decode bitmap,在Android中使用BitmapFactory.decodeStream()从缓存中加载图像

更新:即使我不从缓存中检索图像,我也试图通过Drawable进行检索,其中我将所有18个图像存储在“drawable-mdpi”文件夹中。仍然显示一个空白屏幕。我能够从服务器检索图像并将图像(.GIF)保存到缓存中。但是,当我需要从缓存中加载该图像时,图像不会显示在屏幕上。这是做这项工作的代码:File cacheDir = context.getCacheDir();File cacheMap ...

weixin_39723655的博客 770

Android Bitmap图片缩放优化,用canvas替代Matrix进行缩放,解决一些错我

Android Bitmap图片缩放优化,用cavans替代Matrix进行缩放,解决一些错我

xufeifandj的专栏 6315

Android:BitmapFactory.decodeStream Bitmap的内存优化OutOfMemory异常以后Crash闪退

Android:BitmapFactory.decodeStream 异常OOM闪退

u013083465的专栏 2127

Android-Bitmap优化

概述 在日常开发中我们经常遇到加载图片报出oom的错误,我们要解决这个问题,首先要明白oom代表out of memory 内存溢出,因为手机内存有限,分给每个应用的内存有限,所以要解决这个问题就是要解决图片占用内存问题 android 中图片是以bitmap的形式存在的,那么bitmap中所占的内存,直接影响到了是否oom,我们了解一下bitmap的占用内存的计算方法 Bitmap到底占多大内存 从本地加载或者从网络加载可以用下面的公式计算 图片的长度 * 图片的宽度 * 一个像素点占用的字节数 如果

nufuli123的博客 1091

Android进阶之路 - Uri、Path、File、Bitmap 转换方式

在拍照和相册功能中经常能遇到一些uri、path、file、bitmap的相互转换问题,这里主要记录一些Uri、Path、File、Bitmap 转换方式

Android、前端、小程序、后端 1万+

Android 内存优化实例

下面来看两个内存优化的实例,分别从bitmap和代码两个角度来对内存进行优化。 1.bitmap优化 bitmap是造成内存占用过度甚至是OOM(out of memory)的最大威胁。下面给出一些使用bitmap的小技巧。 1).使用适当分辨率和大小的图片 由于android系统在做资源分配的时候会对不同分辨率文件夹下的图片进行缩放来适配相应的分辨率,如果图片的分辨率与资源文件夹分辨率不

qq_28533013的博客 532

ANSYS Fluent 2023R2实战:用欧拉多相流模型搞定流化床模拟(附详细参数避坑)

本文详细解析了ANSYS Fluent 2023R2中欧拉多相流模型在流化床模拟中的应用,包括模型选择、材料属性设置、相间作用力配置及初始化技巧。特别针对高颗粒浓度工况提供参数优化方案,帮助工程师提升模拟精度与效率,适用于化工、能源等领域的流化床反应器设计。

weixin_30938149的博客 269

用Bitmap加载图片资源时,报错java.lang.OutOfMemoryError: bitmap size exceeds VM budget的解决办法

android系统限制,只给图片分配8兆的内存,超过就崩,你图片几十KB,可能是压缩格式的,转换成bitmap就是本来的大小。 在使用模拟器时,出现以上错误,怎么办呢? 1.方法一:增大限制:在设置VM的时候,在Hardware选项中,有一项Max VM application heap size,将该项的值增大(默认值是24,可以增到60等等) 2.方法二:压缩图片,并及时

huakai521的专栏 320

[LaTeX] 调整参考文献的格式(References),包括作者名缩写,行距,字体,引用顺序等等

在此记录我对LaTeX中参考文献references的尝试,主要涵盖如题几个方面。

the Blog of 等不到天亮丶等时光 4万+

手把手教你用vLLM在昇腾910B上部署Qwen3-Embedding-8B模型(保姆级避坑指南)

本文详细介绍了如何在昇腾910B芯片上使用vLLM推理引擎部署Qwen3-Embedding-8B模型的全流程,包括环境准备、vLLM-ascend定制化安装、模型获取与校验、环境变量配置、服务启动参数优化、性能压测及生产级部署建议。特别针对昇腾生态的开发者,提供了保姆级的避坑指南和实用技巧,帮助实现高效稳定的模型部署。

weixin_28726671的博客 465

解决Android解析图片的OOM问题!!!(转)

大家好,今天给大家分享的是解决解析图片的出现oom的问题,我们可以用BitmapFactory这里的各种Decode方法,如果图片很小的话,不会出现oom,但是当图片很大的时候 就要用BitmapFactory.Options这个东东了,Options里主要有两个参数比较重要. [java] view plaincopy   options.inJustDecodeBo...

weixin_34268579的博客 110

具身机器人内部PCB板分类与系统架构详解

本文系统梳理了机器人内部PCB板的功能架构,将其划分为5大模块:1)核心主板(含主控计算机板、实时控制板等);2)感知类PCB(视觉、听觉、触觉等);3)运动控制类PCB(伺服驱动、编码器等);4)电源与安全类PCB(电源管理、BMS等);5)通信类PCB(EtherCAT背板等)。通过人体器官类比(如大脑对应主控板、小脑对应实时控制板),详解了各模块的芯片选型、位置分布及协同关系,并给出信号/能量/指令的三流闭环示意图和典型系统参数(48V供电、1ms通信周期)。整体呈现了机器人"神经系统&qu

几十年资深高级架构师,技术专家的技术笔记。专注C、Java、Python、微服务、云原生、AI工程化及高并发系统分布式架构实战,分享源码剖析、性能调优与架构治理经验。 321

Android性能优化系列之Bitmap图片优化

在不配置Options的情况下: 1.decodeFile、decodeStream在解析时不会对Bitmap进行一系列的屏幕适配,解析出来的将是原始大小的图 2.decodeResource在解析时会对Bitmap根据当前设备屏幕像素密度densityDpi的值进行缩放适配操作,使得解析出来的Bitmap与当前设备的分辨率匹配,达到一个最佳的显示效果,并且Bitmap的大小将比原始的大。2.图片分辨率越高,消耗的内存越大,当加载高分辨率图片的时候,将会非常占用内存,一旦处理不当就会OOM。

Gaga246的博客 1868

[小技巧] 如何复制知乎电子书中的文字和图片

文章目录一、背景二、复制文字1.最简单的方法(适合短小文字)2. 进阶方法(适合大段文字)三、复制图片四、注意事项 一、背景 有时候希望从书中摘录一部分文字作为笔记,但是知乎电子书阅读时候是禁止copy的,要么手打,要么OCR,给学习带来了一些不便。 审查元素后发现,知乎电子书是把文字分成一段一段的,试图F12直接copy不太方便。 本问将以谷歌Chrome浏览器为例,给出复制小技巧。 二、复制文字 1.最简单的方法(适合短小文字) 选中你需要的文字,左键单击不放,直接拖到地址栏。 然后可以从地址栏中

江南蜡笔小新 9246

Polymarket链上预测市场自动化交易代理开发实战指南

自动化交易代理是量化交易的核心工具,它通过预设的算法规则,自动执行市场分析、决策与下单操作,旨在提升交易效率与纪律性。其技术原理通常涉及实时数据获取、策略引擎计算、交易执行与风险管理等模块的协同工作。在区块链与DeFi领域,这类代理的价值尤为凸显,能够高效处理链上合约交互,捕捉去中心化市场的套利机会。具体到应用场景,链上预测市场如Polymarket,为自动化策略提供了丰富的博弈标的。本文以Polymarket交易代理项目为例,深入剖析其基于Node.js与ethers.js的技术栈实现,详解从环境配置、策

weixin_42533910的博客 581

Android 图片性能优化:Bitmap

一、引入         图片作为内存消耗大户,一直是开发人员尝试优化的重点对象。Bitmap的内存从3.0以前的位于native,到后来改成jvm,再到8.0又改回到native。jvm每个进程都有内存上限,而native则没有限制(不是没有影响,至少不会oom),所以把内存大户Bitmap挪到native可能是很多人的梦想,但native的管理和实现明显比jvm更为复杂,除非有现成实现,很少有人去动这一块。 二、初识Bitm

weixin_42814000的博客 3851

【AUTOSAR-E2E】-2.2-配置E2E:基于E2EPW配置一个TX发送的Signal Group(使用E2E Profile 2)

《共13页精讲》:此法也适用于E2E Profile 4/5/6/7/11/22 目录 1 检查CAN Matrix Arxml/DBC是否满足E2E需求 2 在DaVinci Developer中为Port添加E2E保护 3 在DaVinci Configurator settings设置 4 如何使用应用层的E2E保护 5 结尾 <--返回「Autosar_BSW高阶配置」总目录--> <--返回「Autosar_BSW高阶配置」专栏主页--> &lt.

「汽车电子助手」的博客 4219

Android中Bitmap内存优化

Bitmap内存占用 ≈ 像素数据总大小 = 横向像素数量 × 纵向像素数量 × 每个像素的字节大小。

2501_90425664的博客 2062

NLP高频面试题(三十一)——多模态预训练模型的主要结构、特征对齐与融合方法及对比损失函数详解

多模态预训练模型通过创新的架构设计和训练策略,在跨模态理解和表示学习上取得了显著进展。从单塔到双塔,从编码器-解码器混合到图结构模型,研究者们探索了不同的模态融合途径;配合显式与隐式对齐手段以及有效的对比学习损失,当前的多模态模型已经能够在图文检索、视觉问答、图像描述生成等任务上接近甚至超越专门的有监督模型。可以说,多模态预训练成为了继NLP和CV单模态预训练之后的又一个AI热点领域。模型规模与泛化:与单模态的大型预训练模型类似,多模态模型的参数规模和训练数据规模在迅速增长。

WeLearnNLP 2924

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Android Bitmap详解

一、Bitmap: Bitmap是Android系统中的图像处理的最重要类之一。用它可以获取图像文件信息,进行图像剪切、旋转、缩放等操作,并可以指定格式保存图像文件。 常用方法: public void recycle()  // 回收位图占用的内存空间,把位图标记为Dead public fina...

假装你是大灰狼的专栏 6084

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Android-Bitmap图片优化

Android-Bitmap图片优化前言思考优化点案例 前言 A:透明度 R:红色 G:绿 B:蓝 Bitmap.Config ARGB_4444:每个像素占四位,即A=4,R=4,G=4,B=4,那么一个像素点占4+4+4+4=16位; Bitmap.Config ARGB_8888:每个像素占八位,即A=8,R=8,G=8,B=8,那么一个像素点占8+8+8+8=32位; Bitmap.Config RGB_565:每个像素占四位,即R=5,G=6,B=5,没有透明度,那么一个像素点占5+6+5=16

weixin_43506260的博客 674

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

下一篇: Kail linux之ARP欺骗测试
Crcker
博客等级 码龄10年 17粉丝 25原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值