本文整理匯總了Java中android.graphics.Bitmap.Config.RGB_565屬性的典型用法代碼示例。如果您正苦於以下問題:Java Config.RGB_565屬性的具體用法?Java Config.RGB_565怎麽用?Java Config.RGB_565使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.graphics.Bitmap.Config
的用法示例。
在下文中一共展示了Config.RGB_565屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getBytesPerPixel
/**
* Return the byte usage per pixel of a bitmap based on its configuration.
* @param config The bitmap configuration.
* @return The byte usage per pixel.
*/
private static int getBytesPerPixel(Config config) {
if (config == Config.ARGB_8888) {
return 4;
} else if (config == Config.RGB_565) {
return 2;
} else if (config == Config.ARGB_4444) {
return 2;
} else if (config == Config.ALPHA_8) {
return 1;
}
return 1;
}
示例2: makeImageRequest
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
ScaleType scaleType, final String cacheKey) {
return new ImageRequest(requestUrl, new Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
onGetImageSuccess(cacheKey, response);
}
}, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
onGetImageError(cacheKey, error);
}
});
}
示例3: getBitmapFromResource
/**
* 獲取一個指定大小的bitmap
*
* @param res Resources
* @param resId 圖片ID
* @param reqWidth 目標寬度
* @param reqHeight 目標高度
*/
public static Bitmap getBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// BitmapFactory.Options options = new BitmapFactory.Options();
// options.inJustDecodeBounds = true;
// BitmapFactory.decodeResource(res, resId, options);
// options = BitmapHelper.calculateInSampleSize(options, reqWidth,
// reqHeight);
// return BitmapFactory.decodeResource(res, resId, options);
// 通過JNI的形式讀取本地圖片達到節省內存的目的
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Config.RGB_565;
options.inPurgeable = true;
options.inInputShareable = true;
InputStream is = res.openRawResource(resId);
return getBitmapFromStream(is, null, reqWidth, reqHeight);
}
示例4: b
private static final boolean b(String str, int i, int i2) {
if (TextUtils.isEmpty(str)) {
return false;
}
Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(str, options);
int i3 = options.outWidth;
int i4 = options.outHeight;
if (options.mCancel || options.outWidth == -1 || options.outHeight == -1) {
return false;
}
int i5 = i3 > i4 ? i3 : i4;
if (i3 >= i4) {
i3 = i4;
}
f.b("AsynScaleCompressImage", "longSide=" + i5 + "shortSide=" + i3);
options.inPreferredConfig = Config.RGB_565;
if (i5 > i2 || i3 > i) {
return true;
}
return false;
}
示例5: verifyResize
private void verifyResize(NetworkResponse networkResponse, int maxWidth, int maxHeight,
ScaleType scaleType, int expectedWidth, int expectedHeight) {
ImageRequest request = new ImageRequest("", null, maxWidth, maxHeight, scaleType,
Config.RGB_565, null);
Response<Bitmap> response = request.parseNetworkResponse(networkResponse);
assertNotNull(response);
assertTrue(response.isSuccess());
Bitmap bitmap = response.result;
assertNotNull(bitmap);
assertEquals(expectedWidth, bitmap.getWidth());
assertEquals(expectedHeight, bitmap.getHeight());
}
示例6: makeImageRequest
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType, final String cacheKey) {
return new ImageRequest(requestUrl, new Listener<Bitmap>() {
public void onResponse(Bitmap response) {
ImageLoader.this.onGetImageSuccess(cacheKey, response);
}
}, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
public void onErrorResponse(VolleyError error) {
ImageLoader.this.onGetImageError(cacheKey, error);
}
});
}
示例7: getBytesPerPixel
/**
* Return the byte usage per pixel of a bitmap based on its configuration.
*
* @param config
* The bitmap configuration.
* @return The byte usage per pixel.
*/
private static int getBytesPerPixel(Config config) {
if (config == Config.ARGB_8888) {
return 4;
} else if (config == Config.RGB_565) {
return 2;
} else if (config == Config.ARGB_4444) {
return 2;
} else if (config == Config.ALPHA_8) {
return 1;
}
return 1;
}
示例8: readBitMap
/**
* 以最省內存的方式讀取本地資源的圖片
*
* @param context
* @param resId
* @return
*/
public static Bitmap readBitMap(Context context, int resId) {
Options opt = new Options();
opt.inPreferredConfig = Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
// 獲取資源圖片
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is, null, opt);
}
示例9: verifyResize
private void verifyResize(NetworkResponse networkResponse, int maxWidth, int maxHeight,
int expectedWidth, int expectedHeight) {
ImageRequest request = new ImageRequest(
"", null, maxWidth, maxHeight, Config.RGB_565, null);
Response<Bitmap> response = request.parseNetworkResponse(networkResponse);
assertNotNull(response);
assertTrue(response.isSuccess());
Bitmap bitmap = response.result;
assertNotNull(bitmap);
assertEquals(expectedWidth, bitmap.getWidth());
assertEquals(expectedHeight, bitmap.getHeight());
}
示例10: ratio
/**
* Compress image by pixel, this will modify image width/height.
* Used to get thumbnail
*
* @param imgPath image path
* @param pixelW target pixel of width
* @param pixelH target pixel of height
* @return
*/
public Bitmap ratio(String imgPath, float pixelW, float pixelH) {
BitmapFactory.Options newOpts = new BitmapFactory.Options();
// 開始讀入圖片,此時把options.inJustDecodeBounds 設回true,即隻讀邊不讀內容
newOpts.inJustDecodeBounds = true;
newOpts.inPreferredConfig = Config.RGB_565;
// Get bitmap info, but notice that bitmap is null now
Bitmap bitmap = BitmapFactory.decodeFile(imgPath, newOpts);
newOpts.inJustDecodeBounds = false;
int w = newOpts.outWidth;
int h = newOpts.outHeight;
// 想要縮放的目標尺寸
float hh = pixelH;// 設置高度為240f時,可以明顯看到圖片縮小了
float ww = pixelW;// 設置寬度為120f,可以明顯看到圖片縮小了
// 縮放比。由於是固定比例縮放,隻用高或者寬其中一個數據進行計算即可
int be = 1;//be=1表示不縮放
if (w > h && w > ww) {//如果寬度大的話根據寬度固定大小縮放
be = (int) (newOpts.outWidth / ww);
} else if (w < h && h > hh) {//如果高度高的話根據寬度固定大小縮放
be = (int) (newOpts.outHeight / hh);
}
if (be <= 0) be = 1;
newOpts.inSampleSize = be;//設置縮放比例
// 開始壓縮圖片,注意此時已經把options.inJustDecodeBounds 設回false了
bitmap = BitmapFactory.decodeFile(imgPath, newOpts);
// 壓縮好比例大小後再進行質量壓縮
// return compress(bitmap, maxSize); // 這裏再進行質量壓縮的意義不大,反而耗資源,刪除
return bitmap;
}
示例11: getBitmap
public static Bitmap getBitmap(InputStream inputStream, int i) {
if (inputStream == null) {
return null;
}
Options options = new Options();
options.inPreferredConfig = Config.RGB_565;
options.inPurgeable = true;
options.inInputShareable = true;
options.inSampleSize = i;
return BitmapFactory.decodeStream(inputStream, null, options);
}
示例12: calculateConfig
@SuppressWarnings("deprecation")
private void calculateConfig(
InputStream is,
DecodeFormat format,
boolean isHardwareConfigAllowed,
boolean isExifOrientationRequired,
BitmapFactory.Options optionsWithScaling,
int targetWidth,
int targetHeight) {
if (hardwareConfigState.setHardwareConfigIfAllowed(
targetWidth,
targetHeight,
optionsWithScaling,
format,
isHardwareConfigAllowed,
isExifOrientationRequired)) {
return;
}
// Changing configs can cause skewing on 4.1, see issue #128.
if (format == DecodeFormat.PREFER_ARGB_8888
|| format == DecodeFormat.PREFER_ARGB_8888_DISALLOW_HARDWARE
|| Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
optionsWithScaling.inPreferredConfig = Bitmap.Config.ARGB_8888;
return;
}
boolean hasAlpha = false;
try {
hasAlpha = ImageHeaderParserUtils.getType(parsers, is, byteArrayPool).hasAlpha();
} catch (IOException e) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Cannot determine whether the image has alpha or not from header"
+ ", format " + format, e);
}
}
optionsWithScaling.inPreferredConfig =
hasAlpha ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
if (optionsWithScaling.inPreferredConfig == Config.RGB_565) {
optionsWithScaling.inDither = true;
}
}
示例13: get
/**
* Issues a bitmap request with the given URL if that image is not available
* in the cache, and returns a bitmap container that contains all of the data
* relating to the request (as well as the default image if the requested
* image is not available).
* @param requestUrl The url of the remote image
* @param imageListener The listener to call when the remote image is loaded
* @param maxWidth The maximum width of the returned image.
* @param maxHeight The maximum height of the returned image.
* @return A container object that contains all of the properties of the request, as well as
* the currently available image (default if remote is not loaded).
*/
public ImageContainer get(String requestUrl, ImageListener imageListener,
int maxWidth, int maxHeight) {
// only fulfill requests that were initiated from the main thread.
throwIfNotOnMainThread();
final String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight);
// Try to look up the request in the cache of remote images.
Bitmap cachedBitmap = mCache.getBitmap(cacheKey);
if (cachedBitmap != null) {
// Return the cached bitmap.
ImageContainer container = new ImageContainer(cachedBitmap, requestUrl, null, null);
imageListener.onResponse(container, true);
return container;
}
// The bitmap did not exist in the cache, fetch it!
ImageContainer imageContainer =
new ImageContainer(null, requestUrl, cacheKey, imageListener);
// Update the caller to let them know that they should use the default bitmap.
imageListener.onResponse(imageContainer, true);
// Check to see if a request is already in-flight.
BatchedImageRequest request = mInFlightRequests.get(cacheKey);
if (request != null) {
// If it is, add this request to the list of listeners.
request.addContainer(imageContainer);
return imageContainer;
}
// The request is not already in flight. Send the new request to the network and
// track it.
Request<?> newRequest =
new ImageRequest(requestUrl, new Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
onGetImageSuccess(cacheKey, response);
}
}, maxWidth, maxHeight,
Config.RGB_565, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
onGetImageError(cacheKey, error);
}
});
mRequestQueue.add(newRequest);
mInFlightRequests.put(cacheKey,
new BatchedImageRequest(newRequest, imageContainer));
return imageContainer;
}
示例14: a
protected Request a(String str, int i, int i2, ScaleType scaleType, String str2) {
return new n(str, new h(this, str2), i, i2, scaleType, Config.RGB_565);
}