use of android.graphics.Bitmap in project ion by koush.
the class IonBitmapCache method loadBitmap.
public static Bitmap loadBitmap(byte[] bytes, int offset, int length, BitmapFactory.Options o) {
assert Thread.currentThread() != Looper.getMainLooper().getThread();
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, offset, length, o);
if (bitmap == null)
return null;
int rotation = Exif.getOrientation(bytes, offset, length);
return getRotatedBitmap(bitmap, rotation);
}
use of android.graphics.Bitmap in project ion by koush.
the class IonBitmapCache method loadBitmap.
public static Bitmap loadBitmap(InputStream stream, BitmapFactory.Options o) throws IOException {
assert Thread.currentThread() != Looper.getMainLooper().getThread();
int rotation;
MarkableInputStream in = new MarkableInputStream(stream);
in.mark(50000);
try {
byte[] bytes = new byte[50000];
int length = in.read(bytes);
rotation = Exif.getOrientation(bytes, 0, length);
} catch (Exception e) {
rotation = 0;
}
in.reset();
Bitmap bitmap = BitmapFactory.decodeStream(in, null, o);
return getRotatedBitmap(bitmap, rotation);
}
use of android.graphics.Bitmap in project ion by koush.
the class BitmapTests method test404.
public void test404() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.listen(5566);
try {
final Semaphore semaphore = new Semaphore(0);
Ion.with(getContext()).load("http://localhost:5566/foo.png").asBitmap().setCallback(new FutureCallback<Bitmap>() {
@Override
public void onCompleted(Exception e, Bitmap result) {
semaphore.release();
assertNotNull(e);
}
});
semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS);
Ion.with(getContext()).load("http://localhost:5566/foo.png").asBitmap().setCallback(new FutureCallback<Bitmap>() {
@Override
public void onCompleted(Exception e, Bitmap result) {
semaphore.release();
assertNotNull(e);
}
});
semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS);
} finally {
httpServer.stop();
AsyncServer.getDefault().stop();
}
}
use of android.graphics.Bitmap in project ion by koush.
the class BitmapTests method testCropping.
public void testCropping() throws Exception {
Bitmap result = Ion.with(getContext()).load("https://raw.githubusercontent.com/koush/ion/master/ion/test/assets/exif.jpg").withBitmap().resize(1080, 1845).centerCrop().asBitmap().get();
assertEquals(result.getWidth(), 1080);
assertEquals(result.getHeight(), 1845);
// pixel should not be clear
int pixel = result.getPixel(1079, 1844);
System.out.println(String.format("%x", pixel));
assertFalse(0 == pixel);
}
use of android.graphics.Bitmap in project Lazy by l123456789jy.
the class BitmapUtil method emboss.
/**
* 浮雕效果处理
*
* @param bitmap 原图
* @return 浮雕效果处理后的图片
*/
public static Bitmap emboss(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
int pixR = 0;
int pixG = 0;
int pixB = 0;
int pixColor = 0;
int newR = 0;
int newG = 0;
int newB = 0;
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
int pos = 0;
for (int i = 1, length = height - 1; i < length; i++) {
for (int k = 1, len = width - 1; k < len; k++) {
pos = i * width + k;
pixColor = pixels[pos];
pixR = Color.red(pixColor);
pixG = Color.green(pixColor);
pixB = Color.blue(pixColor);
pixColor = pixels[pos + 1];
newR = Color.red(pixColor) - pixR + 127;
newG = Color.green(pixColor) - pixG + 127;
newB = Color.blue(pixColor) - pixB + 127;
newR = Math.min(255, Math.max(0, newR));
newG = Math.min(255, Math.max(0, newG));
newB = Math.min(255, Math.max(0, newB));
pixels[pos] = Color.argb(255, newR, newG, newB);
}
}
newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return newBitmap;
}
Aggregations