Search in sources :

Example 71 with Bitmap

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);
}
Also used : Bitmap(android.graphics.Bitmap) Point(android.graphics.Point)

Example 72 with Bitmap

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);
}
Also used : Bitmap(android.graphics.Bitmap) Point(android.graphics.Point) IOException(java.io.IOException)

Example 73 with Bitmap

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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) AsyncHttpServer(com.koushikdutta.async.http.server.AsyncHttpServer) Semaphore(java.util.concurrent.Semaphore)

Example 74 with Bitmap

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);
}
Also used : Bitmap(android.graphics.Bitmap)

Example 75 with Bitmap

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;
}
Also used : Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

Bitmap (android.graphics.Bitmap)3746 Canvas (android.graphics.Canvas)889 Paint (android.graphics.Paint)709 BitmapDrawable (android.graphics.drawable.BitmapDrawable)461 IOException (java.io.IOException)394 Rect (android.graphics.Rect)341 File (java.io.File)262 Test (org.junit.Test)255 Matrix (android.graphics.Matrix)254 Drawable (android.graphics.drawable.Drawable)243 BitmapFactory (android.graphics.BitmapFactory)240 View (android.view.View)225 ImageView (android.widget.ImageView)210 Intent (android.content.Intent)187 FileOutputStream (java.io.FileOutputStream)186 InputStream (java.io.InputStream)171 RectF (android.graphics.RectF)150 FileNotFoundException (java.io.FileNotFoundException)150 Point (android.graphics.Point)148 Uri (android.net.Uri)128