Java Code Examples for android.graphics.Bitmap.Config#RGB_565
The following examples show how to use
android.graphics.Bitmap.Config#RGB_565 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnimationsContainer.java From FimiX8-RE with MIT License | 6 votes |
public FramesSequenceAnimation(ImageView imageView, int[] frames, int fps) { this.mFrames = frames; this.mIndex = -1; this.mSoftReferenceImageView = new SoftReference(imageView); this.mShouldRun = false; this.mIsRunning = false; this.mDelayMillis = 100; imageView.setImageResource(this.mFrames[0]); if (VERSION.SDK_INT >= 11) { Bitmap bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); this.mBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig()); this.mBitmapOptions = new Options(); this.mBitmapOptions.inBitmap = this.mBitmap; this.mBitmapOptions.inMutable = true; this.mBitmapOptions.inSampleSize = 1; this.mBitmapOptions.inPreferredConfig = Config.RGB_565; } }
Example 2
Source File: ImageLoader.java From volley with Apache License 2.0 | 6 votes |
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); } }); }
Example 3
Source File: PLUtils.java From panoramagl with Apache License 2.0 | 6 votes |
/** * conversion methods */ public static Config convertTextureColorFormatToBitmapConfig(PLTextureColorFormat colorFormat) { Config config = Config.ARGB_8888; switch (colorFormat) { case PLTextureColorFormatRGB565: config = Config.RGB_565; break; case PLTextureColorFormatRGBA4444: config = Config.ARGB_4444; break; default: break; } return config; }
Example 4
Source File: ImageLoader.java From device-database with Apache License 2.0 | 5 votes |
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); } }); }
Example 5
Source File: ImageRequestTest.java From SaveVolley with Apache License 2.0 | 5 votes |
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()); }
Example 6
Source File: DrawableBitmapResourceDecoder.java From glide-support with The Unlicense | 5 votes |
@Override public Resource<Bitmap> decode(Drawable drawable, int width, int height) throws IOException { Config config = PixelFormat.formatHasAlpha(drawable.getOpacity())? Config.ARGB_8888 : Config.RGB_565; Bitmap bitmap = pool.get(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), config); if (bitmap == null) { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), config); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return new BitmapResource(bitmap, pool); }
Example 7
Source File: ImageRequestTest.java From CrossBow with Apache License 2.0 | 5 votes |
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()); }
Example 8
Source File: ImageLoader.java From okulus with Apache License 2.0 | 5 votes |
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight, final String cacheKey) { return 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); } }); }
Example 9
Source File: ImageCache.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 10
Source File: SubsamplingScaleImageView.java From light-novel-library_Wenku8_Android with GNU General Public License v2.0 | 5 votes |
@Override protected Bitmap doInBackground(Void... params) { try { if (decoderRef != null && tileRef != null && viewRef != null) { final BitmapRegionDecoder decoder = decoderRef.get(); final Object decoderLock = decoderLockRef.get(); final Tile tile = tileRef.get(); final SubsamplingScaleImageView view = viewRef.get(); if (decoder != null && decoderLock != null && tile != null && view != null && !decoder.isRecycled()) { synchronized (decoderLock) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = tile.sampleSize; options.inPreferredConfig = Config.RGB_565; options.inDither = true; Bitmap bitmap = decoder.decodeRegion(view.fileSRect(tile.sRect), options); int rotation = view.getRequiredRotation(); if (rotation != 0) { Matrix matrix = new Matrix(); matrix.postRotate(rotation); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } return bitmap; } } else if (tile != null) { tile.loading = false; } } } catch (Exception e) { Log.e(TAG, "Failed to decode tile", e); } return null; }
Example 11
Source File: ImageRequestTest.java From android-project-wo2b with Apache License 2.0 | 5 votes |
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()); }
Example 12
Source File: ImageLoader.java From DaVinci with Apache License 2.0 | 5 votes |
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); } }); }
Example 13
Source File: SkiaImageRegionDecoder.java From PictureSelector with Apache License 2.0 | 5 votes |
@Override public Bitmap decodeRegion(Rect sRect, int sampleSize) { synchronized (decoderLock) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = sampleSize; options.inPreferredConfig = Config.RGB_565; Bitmap bitmap = decoder.decodeRegion(sRect, options); if (bitmap == null) { throw new RuntimeException("Skia image decoder returned null bitmap - image format may not be supported"); } return bitmap; } }
Example 14
Source File: SkiaImageRegionDecoder.java From RxTools-master with Apache License 2.0 | 5 votes |
@Override public Bitmap decodeRegion(Rect sRect, int sampleSize) { synchronized (decoderLock) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = sampleSize; options.inPreferredConfig = Config.RGB_565; Bitmap bitmap = decoder.decodeRegion(sRect, options); if (bitmap == null) { throw new RuntimeException("Skia image decoder returned null bitmap - image format may not be supported"); } return bitmap; } }
Example 15
Source File: BitmapDecoder.java From simple_imageloader with MIT License | 5 votes |
/** * @param options * @param width * @param height * @param lowQuality */ protected void configBitmapOptions(Options options, int width, int height) { // 设置缩放比例 options.inSampleSize = computeInSmallSize(options, width, height); Log.d("", "$## inSampleSize = " + options.inSampleSize + ", width = " + width + ", height= " + height); // 图片质量 options.inPreferredConfig = Config.RGB_565; // 设置为false,解析Bitmap对象加入到内存中 options.inJustDecodeBounds = false; options.inPurgeable = true; options.inInputShareable = true; }
Example 16
Source File: SkiaImageRegionDecoder.java From Matisse-Kotlin with Apache License 2.0 | 5 votes |
@Override public Bitmap decodeRegion(Rect sRect, int sampleSize) { synchronized (decoderLock) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = sampleSize; options.inPreferredConfig = Config.RGB_565; Bitmap bitmap = decoder.decodeRegion(sRect, options); if (bitmap == null) { throw new RuntimeException("Skia image decoder returned null bitmap - image format may not be supported"); } return bitmap; } }
Example 17
Source File: BitmapUtil.java From qrcode_android with GNU Lesser General Public License v3.0 | 5 votes |
public static byte[] createSizeThumbnail(Bitmap bitmap, int size) { if (bitmap == null || bitmap.isRecycled() || size == 0) { return null; } byte[] bytes = BitmapUtil.bitmap2Bytes(bitmap, 100); int loopTime = 0; while (bytes.length > size) { BitmapFactory.Options options = new BitmapFactory.Options(); switch (loopTime) { case 0: bytes = BitmapUtil.bitmap2Bytes(bitmap, 80); options.inPreferredConfig = Config.RGB_565; break; case 1: bytes = BitmapUtil.bitmap2Bytes(bitmap, 40); options.inPreferredConfig = Config.RGB_565; break; case 2: bytes = BitmapUtil.bitmap2Bytes(bitmap, 20); options.inPreferredConfig = Config.RGB_565; break; case 3: bytes = BitmapUtil.bitmap2Bytes(bitmap, 10); options.inPreferredConfig = Config.RGB_565; break; case 4: bytes = BitmapUtil.bitmap2Bytes(bitmap, 5); options.inPreferredConfig = Config.RGB_565; break; default: return bytes; } loopTime++; } return bytes; }
Example 18
Source File: ImageCache.java From graphics-samples with Apache License 2.0 | 5 votes |
/** * 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; }
Example 19
Source File: ImageLoader.java From WayHoo with Apache License 2.0 | 4 votes |
/** * 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; }
Example 20
Source File: Global.java From Favorite-Android-Client with Apache License 2.0 | 4 votes |
/** * 지정한 패스의 파일을 읽어서 Bitmap을 리턴 (화면사이즈에 최다한 맞춰서 리스케일한다.) * * @param context * application context * @param imgFilePath * bitmap file path * @return Bitmap * @throws IOException */ public static Bitmap loadBackgroundBitmap(Context context, String imgFilePath) throws Exception, OutOfMemoryError { // if (!FileUtil.exists(imgFilePath)) { // throw new FileNotFoundException("background-image file not found : " // + imgFilePath); // } // 폰의 화면 사이즈를 구한다. // Display display = ((WindowManager) context // .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); // int displayWidth = display.getWidth(); // int displayHeight = display.getHeight(); // // 읽어들일 이미지의 사이즈를 구한다. BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Config.RGB_565; options.inJustDecodeBounds = true; BitmapFactory.decodeFile(imgFilePath, options); // 화면 사이즈에 가장 근접하는 이미지의 리스케일 사이즈를 구한다. // 리스케일의 사이즈는 짝수로 지정한다. (이미지 손실을 최소화하기 위함.) // float widthScale = options.outWidth / displayWidth; // float heightScale = options.outHeight / displayHeight; // float scale = widthScale > heightScale ? widthScale : heightScale; // // if(scale >= 8) { // options.inSampleSize = 8; // } else if(scale >= 6) { // options.inSampleSize = 6; // } else if(scale >= 4) { // options.inSampleSize = 4; // } else if(scale >= 2) { // options.inSampleSize = 2; // } else { // options.inSampleSize = 1; // } options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(imgFilePath, options); }