Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1027)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapUtils.java

Issue 2845773003: Photo Picker Dialog: Add caching for the decoded images. (Closed)
Patch Set: Remove dead var Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.photo_picker; 5 package org.chromium.chrome.browser.photo_picker;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 import android.graphics.BitmapFactory; 8 import android.graphics.BitmapFactory;
9 9
10 import java.io.FileDescriptor; 10 import java.io.FileDescriptor;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 int x = 0; 100 int x = 0;
101 int y = 0; 101 int y = 0;
102 int width = bitmap.getWidth(); 102 int width = bitmap.getWidth();
103 int height = bitmap.getHeight(); 103 int height = bitmap.getHeight();
104 if (width == size && height == size) return bitmap; 104 if (width == size && height == size) return bitmap;
105 105
106 if (width > size) x = (width - size) / 2; 106 if (width > size) x = (width - size) / 2;
107 if (height > size) y = (height - size) / 2; 107 if (height > size) y = (height - size) / 2;
108 return Bitmap.createBitmap(bitmap, x, y, size, size); 108 return Bitmap.createBitmap(bitmap, x, y, size, size);
109 } 109 }
110
111 /**
112 * Scales a |bitmap| to a certain size.
113 * @param bitmap The bitmap to scale.
114 * @param scaleMaxSize What to scale it to.
115 * @param filter True if the source should be filtered.
116 * @return The resulting scaled bitmap.
117 */
118 public static Bitmap scale(Bitmap bitmap, float scaleMaxSize, boolean filter ) {
119 float ratio = Math.min((float) scaleMaxSize / bitmap.getWidth(),
120 (float) scaleMaxSize / bitmap.getHeight());
121 int height = Math.round(ratio * bitmap.getHeight());
122 int width = Math.round(ratio * bitmap.getWidth());
123
124 return Bitmap.createScaledBitmap(bitmap, width, height, filter);
125 }
110 } 126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698