如何在 android 2.2.2 (Froyo) 中使用 BitmapRegionDecoder 代码? [英] How can I use BitmapRegionDecoder code in android 2.2.2 (Froyo)?

查看:13
本文介绍了如何在 android 2.2.2 (Froyo) 中使用 BitmapRegionDecoder 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读关于 SO 的另一个问题的答案,其中@RomainGuy 评论说可以(请更正如果我的解释不正确)将代码从更高版本的 android 移植到早期版本.具体来说,我对将 BitmapRegionDecoder 的代码从 Android 版本 2.3.3 (Gingerbread) 向后移植到版本 2.2.2 (Froyo) 感兴趣.

I was reading an answer to a different question on SO, in which @RomainGuy commented that one could (please correct me if I'm paraphrasing incorrectly) back-port code from later versions of android to earlier versions. Specifically, I am interested in back-porting code for BitmapRegionDecoder from Android version 2.3.3 (Gingerbread) to version 2.2.2 (Froyo).

我宁愿更一般地问这个问题,因为最佳实践是什么/将代码从较新版本的 Android 向后移植到较旧版本时应避免什么,但 stackoverflow 暗示我的问题可能因过于主观而被关闭.

I would have rather asked the question more generally as what is the best practice / what should be avoided when back-porting code from newer versions of Android to older versions, but stackoverflow hinted that my question might be closed as being too subjective.

也许如果对该主题有足够的兴趣,这个问题可以变形"为更一般的问题..可能是社区维基?

Maybe if there is enough interest in the topic, this question could be "morphed" into a more general one..possibly a community wiki?

无论如何,我希望能深入了解这是如何完成的……无论是特定于我的用例,还是更一般的建议.从 java 类中调用本机方法是否会使问题复杂化(必然涉及 NDK)?

In any case, I would appreciate any insight into how this is done..whether specific to my use case, or more general advice. Do calls to native methods from within the java class complicate the matter (necessarily involving the NDK)?

如果确实有可能(并且合理)以这种方式挑选和向后移植代码,我认为许多人会发现知道如何操作非常有用.

If it is indeed possible (and reasonable) to cherry-pick and back-port code in this way, I think many would find it very useful to know how.

推荐答案

正如@hackbod 提到的 BitmapRegionDecoder 基于外部 skia 库.然而,这可能是一个好处.

As @hackbod mentioned BitmapRegionDecoder is based on external skia library. Yet it's may be a benefit.

让我们检查原始来源:

  • BitmapRegionDecoder.java.主要围绕本机方法定义包装器:

  • BitmapRegionDecoder.java. Mostly defines wrappers around native methods:

private static native Bitmap nativeDecodeRegion(int lbm,
    int start_x, int start_y, int width, int height,
    BitmapFactory.Options options);
private static native int nativeGetWidth(int lbm);
private static native int nativeGetHeight(int lbm);
private static native void nativeClean(int lbm);
// ...multiply nativeNewInstance overloads follow

Class 不使用任何我们需要向后移植的新 Java API.

Class doesn't use any new Java APIs we'd need to backport.

BitmapRegionDecoder.cpp.它包含的头文件由出现在 Froyo 中的头文件组成,除了这两个:

BitmapRegionDecoder.cpp. Header files it includes consist of ones which are present in Froyo except these two:

  • AutoDecodeCancel.h.它用于的唯一行:

AutoDecoderCancel   adc(options, decoder);

此类处理 SkDecoder 实例生命周期.这是一小段代码,可以很好地向后移植.

This class handles SkDecoder instances lifecycle. It's a small piece of code and may be well back-ported.

SkBitmapRegionDecoder.h

正如文件名所述,这是一个核心组件.事实上,之前的所有内容都是围绕它的一种包装.好消息是我们可能不需要向后移植它,因为应该可以从 Gingerbeard 中获取整个 skia 库并在 Froyo 下编译它 因为它是外部的并且不包含任何新的依赖项.

As filename states this is a core component. In fact, all previous were a kind of wrappers around it. The good news is that we may not need to back-port it as it should be possible to take a whole skia library from the Gingerbeard and compile it under Froyo as it is external and doesn't contain any new dependencies.

附言我实际上并没有深入研究代码,所以如果我忽略了任何东西,请纠正我.

P.S. I didn't actually dive deep in the code so please correct me if there's anything I overlooked.

我们需要的源代码位于 froyo-releasegingerbread-mr4-release 分支上的以下存储库中:

Source code we need is located in following repositories on branches froyo-release and gingerbread-mr4-release:

  • 外部skia库存储库
    • 头文件位于 include/coreinclude/images
    • Java 代码:graphics/java/android/graphics/BitmapRegionDecoder.java
    • 原生代码:core/jni/android/graphics/...

    这篇关于如何在 android 2.2.2 (Froyo) 中使用 BitmapRegionDecoder 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆