本文整理汇总了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);
}