我正在使用let worldGroundPlaneGeometry = SCNPlane(width: 1000, height: 1000)
let worldGroundPlane = SCNNode()
worldGroundPlane.geometry?.firstMaterial?.lightingModel = .constant
worldGroundPlane.geometry?.firstMaterial?.writesToDepthBuffer = true
worldGroundPlane.geometry?.firstMaterial?.colorBufferWriteMask = []
worldGroundPlane.geometry = worldGroundPlaneGeometry
worldGroundPlane.position = worldPosition
worldGroundPlane.castsShadow = true
worldGroundPlane.eulerAngles = SCNVector3(Float.pi / 2, 0, 0)
self.addChildNode(worldGroundPlane)
// Create a ambient light
let ambientLight = SCNNode()
ambientLight.light = SCNLight()
ambientLight.light?.shadowMode = .deferred
ambientLight.light?.color = UIColor.white
ambientLight.light?.type = SCNLight.LightType.ambient
ambientLight.position = SCNVector3(x: 0,y: 5,z: 0)
// Create a directional light node with shadow
let directionalNode = SCNNode()
directionalNode.light = SCNLight()
directionalNode.light?.type = SCNLight.LightType.directional
directionalNode.light?.color = UIColor.white
directionalNode.light?.castsShadow = true
directionalNode.light?.automaticallyAdjustsShadowProjection = true
directionalNode.light?.shadowSampleCount = 64
directionalNode.light?.shadowMode = .deferred
directionalNode.light?.shadowMapSize = CGSize(width: 2048, height: 2048)
directionalNode.light?.shadowColor = UIColor.black.withAlphaComponent(0.75)
directionalNode.position = SCNVector3(x: 0,y: 5,z: 0)
// Add the lights to the container
self.addChildNode(ambientLight)
self.addChildNode(directionalNode)
开发图库应用程序,并且我希望将图像大小存储在数据库中的每个图像,但我无法弄清楚哪个是在数据库中存储大小的最佳方式,如果我选择像“2.5 KB”这样的字符串“”500 MB“或Mb或字节的实数,请指导哪种方法在读写性能方面表现最佳
目前我在RecyclerView
的运行时获取文件大小
这样的RecyclerView
方法
onBindViewHolder
但现在我想存储预定义的大小,请指导我。
修改 如果你仔细阅读我的问题我们为什么要投票我只是想存储图像的大小而不是实际图像例如图像大小是1MB我只想存储大小而不是实际图像所以请停止投票
答案 0 :(得分:1)
通常,存储数字而不是文本更好/更有效。
1)考虑到以下因素,数字可能会减少存储空间: -
INTEGER。该值是有符号整数,存储在1,2,3,4,6或8中 字节取决于值的大小。 Datatypes In SQLite Version 3
getLong
方法,如果您需要为数值目的提取值。2)数字可能更灵活,更容易分类和比较。
您可以轻松地将数字转换为格式化字符串: -
假设一个名为filesizes的表(列名为filesize): -
然后: -
SELECT
CASE
WHEN filesize < 1024 THEN filesize || 'B'
WHEN filesize >= 1024 AND filesize < (1024 * 1024) THEN (filesize / 1024) || 'KB'
WHEN filesize >= (1024 * 1024) AND filesize < (1024 * 1024 * 1024) THEN (filesize / (1024 * 1024)) || 'MB'
WHEN filesize >= (1024 * 1024 * 1024) AND filesize < (1024 * 1024 * 1024 *1024) THEN (filesize / (1024 * 1024 * 1024)) || 'GB'
WHEN filesize >= (1024 * 1024 * 1024 * 1024) THEN (filesize / (1024 * 1024 * 1024 * 1024)) || 'TB'
END AS size
FROM filesizes
会导致: -
以下将提供2个小数点(显然不是字节)的值: -
SELECT
CASE
WHEN filesize < 1024 THEN filesize || 'B'
WHEN filesize >= 1024 AND filesize < (1024 * 1024) THEN ROUND((CAST(filesize AS REAL) / 1024),2) || 'KB'
WHEN filesize >= (1024 * 1024) AND filesize < (1024 * 1024 * 1024) THEN ROUND((CAST(filesize AS REAL) / (1024 * 1024)),2) || 'MB'
WHEN filesize >= (1024 * 1024 * 1024) AND filesize < (1024 * 1024 * 1024 *1024) THEN ROUND((CAST(filesize AS REAL) / (1024 * 1024 * 1024)),2) || 'GB'
WHEN filesize >= (1024 * 1024 * 1024 * 1024) THEN ROUND((CAST(filesize AS REAL) / (1024 * 1024 * 1024 * 1024)),2) || 'TB'
END AS size
FROM filesizes
按照: -
当然缺点是: - ?????
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DBNAME = "ifs";
public static final int DBVERSION = 1;
public static final String TBNAME = "imageinfo";
public static final String IITABLE_ID_COL = BaseColumns._ID;
public static final String IITABLE_IMAGENAME_COL = "image_name";
public static final String IITABLE_IMAGESIZE_COL = "image_filesize";
public static final String IITABLE_FORMATTED_COL = "size";
SQLiteDatabase mDB;
public DatabaseHelper(Context context) {
super(context, DBNAME, null, DBVERSION);
mDB = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
String crtsql = "CREATE TABLE IF NOT EXISTS " +
TBNAME + "(" +
IITABLE_ID_COL + "INTEGER PRIMARY KEY, " +
IITABLE_IMAGENAME_COL + " TEXT, " +
IITABLE_IMAGESIZE_COL + " INTEGER" +
")";
db.execSQL(crtsql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public long insertRow(String imagename, long filesize) {
ContentValues cv = new ContentValues();
cv.put(IITABLE_IMAGENAME_COL,imagename);
cv.put(IITABLE_IMAGESIZE_COL,filesize);
return mDB.insert(TBNAME,null,cv);
}
/*
SELECT filesize,
CASE
WHEN filesize < 1024 THEN filesize|| 'B'
WHEN filesize >= 1024 AND filesize < 1048576 THEN ROUND((CAST(filesize AS REAL) / 1024),2) || 'KB'
WHEN filesize >= 1028576 AND filesize < 1073741824 THEN ROUND((CAST(filesize AS REAL) / 1028576),2) || 'MB'
WHEN filesize >= 1073741824 AND filesize < 1099511627776 THEN ROUND((CAST(filesize AS REAL) /1073741824 ),2) || 'GB'
WHEN filesize >= 1099511627776 THEN ROUND((CAST(filesize AS REAL) /1099511627776 ),2) || 'TB'
END AS size
FROM filesizes
*/
public Cursor getFormattedImageList() {
long kilobytes = 1024,
megabytes = kilobytes * kilobytes,
gigabytes = megabytes * kilobytes,
terabytes = gigabytes * kilobytes;
String formatted_column = "CASE" +
// Bytes
" WHEN " + IITABLE_IMAGESIZE_COL + " < " + kilobytes +
" THEN " + IITABLE_IMAGESIZE_COL + " || 'B'" +
// Kilobytes
" WHEN " + IITABLE_IMAGESIZE_COL + ">= " + kilobytes +
" AND " + IITABLE_IMAGESIZE_COL + " < " + megabytes +
" THEN ROUND((CAST(" +
IITABLE_IMAGESIZE_COL + " AS REAL) / " + kilobytes + "),2) || 'KB'" +
// MegaBytes
" WHEN " + IITABLE_IMAGESIZE_COL + ">= " + megabytes +
" AND " + IITABLE_IMAGESIZE_COL + " < " + gigabytes +
" THEN ROUND((CAST(" +
IITABLE_IMAGESIZE_COL + " AS REAL) / " + megabytes + "),2) || 'MB'" +
// GigaBytes
" WHEN " + IITABLE_IMAGESIZE_COL + ">= " + gigabytes +
" AND " + IITABLE_IMAGESIZE_COL + " < " + terabytes +
" THEN ROUND((CAST(" +
IITABLE_IMAGESIZE_COL + " AS REAL) / " + gigabytes + "),2) || 'GB'" +
// Terabytes
" WHEN " + IITABLE_IMAGESIZE_COL + ">= " + terabytes +
" THEN ROUND((CAST(" +
IITABLE_IMAGESIZE_COL + " AS REAL) / " + terabytes + "),2) || 'TB'" +
" END AS " + IITABLE_FORMATTED_COL;
Log.d("SQLCASE",formatted_column);
String[] columns = new String[]{IITABLE_IMAGENAME_COL,formatted_column,IITABLE_IMAGESIZE_COL};
return mDB.query(TBNAME,columns,null,null,null,null,IITABLE_IMAGENAME_COL);
}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Instantiate the Database Helper
DatabaseHelper mDBHlpr = new DatabaseHelper(this);
// Add some rows to the imageinfo table
mDBHlpr.insertRow("The Church",432567L);
mDBHlpr.insertRow("The Shop", 200L);
mDBHlpr.insertRow("The Green", 123456789L);
mDBHlpr.insertRow("The Petrol Station", (1024L * 1024L * 1024L) + 24L);
mDBHlpr.insertRow("The House", 1234567890104444440L);
// Extract a formatted list
Cursor csr = mDBHlpr.getFormattedImageList();
while (csr.moveToNext()) {
Log.d("IMAGES",
"Image is " +
csr.getString(
csr.getColumnIndex(
DatabaseHelper
.IITABLE_IMAGENAME_COL
)
) +
" Size is " +
csr.getString(
csr.getColumnIndex(
DatabaseHelper
.IITABLE_FORMATTED_COL
)
) +
" (" +
String.valueOf(
csr.getLong(
csr.getColumnIndex(
DatabaseHelper
.IITABLE_IMAGESIZE_COL
))) +
")"
);
}
csr.close();
}
}
01-10 21:57:36.552 2619-2619/? D/SQLCASE: CASE WHEN image_filesize < 1024 THEN image_filesize || 'B' WHEN image_filesize>= 1024 AND image_filesize < 1048576 THEN ROUND((CAST(image_filesize AS REAL) / 1024),2) || 'KB' WHEN image_filesize>= 1048576 AND image_filesize < 1073741824 THEN ROUND((CAST(image_filesize AS REAL) / 1048576),2) || 'MB' WHEN image_filesize>= 1073741824 AND image_filesize < 1099511627776 THEN ROUND((CAST(image_filesize AS REAL) / 1073741824),2) || 'GB' WHEN image_filesize>= 1099511627776 THEN ROUND((CAST(image_filesize AS REAL) / 1099511627776),2) || 'TB' END AS size
01-10 21:57:36.552 2619-2619/? D/IMAGES: Image is The Church Size is 422.43KB (432567)
01-10 21:57:36.552 2619-2619/? D/IMAGES: Image is The Green Size is 117.74MB (123456789)
01-10 21:57:36.552 2619-2619/? D/IMAGES: Image is The House Size is 1122832.96TB (1234567890104444440)
01-10 21:57:36.552 2619-2619/? D/IMAGES: Image is The Petrol Station Size is 1.0GB (1073741848)
01-10 21:57:36.552 2619-2619/? D/IMAGES: Image is The Shop Size is 200B (200)