且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的,Drawable.createFromStream(是,源名):什么是第二个参数的含义?

更新时间:2022-10-15 19:44:27

这是基本没用

根据 href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/drawable/Drawable.java#Drawable.drawableFromBitmap%28android.content.res.Resources%2Candroid.graphics.Bitmap%2Cbyte%5b%5d%2Candroid.graphics.Rect%2Cjava.lang.String%29">Froyo源时,它是从资源创建九个补片图像时使用,但创建常规位图时不
  852私有静态绘制对象drawableFromBitmap(资源资源,位图BM,byte []的NP,
853矩形垫,弦乐源名){
854
855如果(NP!= NULL){
856回新NinePatchDrawable(RES,BM,NP,垫,源名);
857}
858
859回新BitmapDrawable(RES,BM);
860}
 

您遵循绘制对象code路线:

createFromStream 返回:

 返回createFromResourceStream(NULL,NULL,是,源名,NULL);
 

这反过来使用:

 返回drawableFromBitmap(RES,BM,NP,垫,源名);
 

(NP来自位图#getNin​​ePatchChunk(); ),这就要求:

 返回新NinePatchDrawable(RES,BM,NP,垫,源名);
 

最后,你到NinePatch声明:

 公共类NinePatch
 

  

创建从一个绘制投影   位图到九补丁。

     

参数

     

位图描述的修补程序的位图。

     

块描述底层怎么位的9补丁数据块   被分开,并绘制。

     

源名源位图的名称。 可能为空

Which is the meaning of the second parameter of Drawable.createFromStream() method?

From Android APIs I only get:

public static Drawable createFromStream (InputStream is, String srcName)
Create a drawable from an inputstream

In all examples I have read I see they use the string "src": is it the name of the directory where the drawable is cached, relative to my application's root dir?

One parallel question: where am I supposed to find Android core sources (for example of Drawable.createFromStream() method...), to avoid such silly questions, in future?

It's basically useless:

Based on Froyo source, it is used when creating nine-patch images from the resource, but not when creating a regular Bitmap:

852 private static Drawable drawableFromBitmap(Resources res, Bitmap bm, byte[] np,
853         Rect pad, String srcName) {
854
855     if (np != null) {
856        return new NinePatchDrawable(res, bm, np, pad, srcName);
857     }
858
859     return new BitmapDrawable(res, bm);
860  }

You get there by following the Drawable code:

createFromStream returns:

return createFromResourceStream(null, null, is, srcName, null);

which in turn uses:

return drawableFromBitmap(res, bm, np, pad, srcName);

(np comes from Bitmap#getNinePatchChunk();) and this calls:

return new NinePatchDrawable(res, bm, np, pad, srcName);

Finally, you get to the NinePatch declaration:

public class NinePatch

Create a drawable projection from a bitmap to nine patches.

Parameters:

bitmap The bitmap describing the patches.

chunk The 9-patch data chunk describing how the underlying bitmap is split apart and drawn.

srcName The name of the source for the bitmap. Might be null.