List of usage examples for android.graphics Bitmap getConfig
public final Config getConfig()
From source file:github.madmarty.madsonic.util.ImageLoader.java
public Bitmap getImageBitmap(String username, int size) { Bitmap bitmap = cache.get(getKey(username, size)); if (bitmap != null && !bitmap.isRecycled()) { Bitmap.Config config = bitmap.getConfig(); return bitmap.copy(config, false); }//from w w w . j a v a 2s . c om return null; }
From source file:github.madmarty.madsonic.util.ImageLoader.java
public Bitmap getImageBitmap(MusicDirectory.Entry entry, boolean large, int size) { if (entry == null) { return null; }//from w w w.j a v a2 s .co m String coverArt = entry.getCoverArt(); if (coverArt == null) { return null; } if (size <= 0) { size = large ? imageSizeLarge : imageSizeDefault; } Bitmap bitmap = cache.get(getKey(coverArt, size)); if (bitmap != null && !bitmap.isRecycled()) { Bitmap.Config config = bitmap.getConfig(); return bitmap.copy(config, false); } return null; }
From source file:Main.java
public static Bitmap fastblur(Bitmap sentBitmap, int radius) { // Stack Blur v1.0 from // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html // Java Author: Mario Klingemann <mario at quasimondo.com> // http://incubator.quasimondo.com // created Feburary 29, 2004 // Android port : Yahel Bouaziz <yahel at kayenko.com> // http://www.kayenko.com // ported april 5th, 2012 // This is a compromise between Gaussian Blur and Box blur // It creates much better looking blurs than Box Blur, but is // 7x faster than my Gaussian Blur implementation. // I called it Stack Blur because this describes best how this // filter works internally: it creates a kind of moving stack // of colors whilst scanning through the image. Thereby it // just has to add one new block of color to the right side // of the stack and remove the leftmost color. The remaining // colors on the topmost layer of the stack are either added on // or reduced by one, depending on if they are on the right or // on the left side of the stack. // If you are using this algorithm in your code please add // the following line: // Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com> Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); if (radius < 1) { return (null); }/*from w w w . j a v a 2 s .c om*/ int w = bitmap.getWidth(); int h = bitmap.getHeight(); int[] pix = new int[w * h]; bitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1; int hm = h - 1; int wh = w * h; int div = radius + radius + 1; int r[] = new int[wh]; int g[] = new int[wh]; int b[] = new int[wh]; int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; int vmin[] = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1; divsum *= divsum; int dv[] = new int[256 * divsum]; for (i = 0; i < 256 * divsum; i++) { dv[i] = (i / divsum); } yw = yi = 0; int[][] stack = new int[div][3]; int stackpointer; int stackstart; int[] sir; int rbs; int r1 = radius + 1; int routsum, goutsum, boutsum; int rinsum, ginsum, binsum; for (y = 0; y < h; y++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { p = pix[yi + Math.min(wm, Math.max(i, 0))]; sir = stack[i + radius]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rbs = r1 - Math.abs(i); rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } } stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (y == 0) { vmin[x] = Math.min(x + radius + 1, wm); } p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[(stackpointer) % div]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi++; } yw += w; } for (x = 0; x < w; x++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } if (i < hm) { yp += w; } } yi = x; stackpointer = radius; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (x == 0) { vmin[y] = Math.min(y + r1, hm) * w; } p = x + vmin[y]; sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]; rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[stackpointer]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi += w; } } bitmap.setPixels(pix, 0, w, 0, 0, w, h); return (bitmap); }
From source file:com.truebanana.bitmap.BitmapUtils.java
@SuppressLint("NewApi") public static Bitmap blur(Context context, Bitmap bitmap, float scale, int radius) { if (SystemUtils.getSDKVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR1) { int width = Math.round(bitmap.getWidth() * scale); int height = Math.round(bitmap.getHeight() * scale); bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false); Bitmap processedBitmap = Bitmap.createBitmap(bitmap); RenderScript rs = RenderScript.create(context); ScriptIntrinsicBlur sib = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation tmpIn = Allocation.createFromBitmap(rs, bitmap); Allocation tmpOut = Allocation.createFromBitmap(rs, processedBitmap); sib.setRadius(radius);/*from w w w .j a v a 2s . c om*/ sib.setInput(tmpIn); sib.forEach(tmpOut); tmpOut.copyTo(processedBitmap); return processedBitmap; } else { int width = Math.round(bitmap.getWidth() * scale); int height = Math.round(bitmap.getHeight() * scale); bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false); Bitmap processedBitmap = bitmap.copy(bitmap.getConfig(), true); if (radius < 1) { return null; } int w = processedBitmap.getWidth(); int h = processedBitmap.getHeight(); int[] pix = new int[w * h]; processedBitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1; int hm = h - 1; int wh = w * h; int div = radius + radius + 1; int r[] = new int[wh]; int g[] = new int[wh]; int b[] = new int[wh]; int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; int vmin[] = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1; divsum *= divsum; int dv[] = new int[256 * divsum]; for (i = 0; i < 256 * divsum; i++) { dv[i] = (i / divsum); } yw = yi = 0; int[][] stack = new int[div][3]; int stackpointer; int stackstart; int[] sir; int rbs; int r1 = radius + 1; int routsum, goutsum, boutsum; int rinsum, ginsum, binsum; for (y = 0; y < h; y++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { p = pix[yi + Math.min(wm, Math.max(i, 0))]; sir = stack[i + radius]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rbs = r1 - Math.abs(i); rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } } stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (y == 0) { vmin[x] = Math.min(x + radius + 1, wm); } p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[(stackpointer) % div]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi++; } yw += w; } for (x = 0; x < w; x++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } if (i < hm) { yp += w; } } yi = x; stackpointer = radius; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (x == 0) { vmin[y] = Math.min(y + r1, hm) * w; } p = x + vmin[y]; sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]; rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[stackpointer]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi += w; } } processedBitmap.setPixels(pix, 0, w, 0, 0, w, h); return processedBitmap; } }
From source file:im.neon.util.NotificationUtils.java
/** * Build a message notification.//from ww w . j a v a 2 s .c om * @param context the context * @param from the sender * @param matrixId the user account id; * @param displayMatrixId true to display the matrix id * @param largeIcon the notification icon * @param unseenNotifiedRoomsCount the number of notified rooms * @param body the message body * @param roomId the room id * @param roomName the room name * @param shouldPlaySound true when the notification as sound. * @param isInvitationEvent true if it is an invitation notification * @return the notification */ public static Notification buildMessageNotification(Context context, String from, String matrixId, boolean displayMatrixId, Bitmap largeIcon, int unseenNotifiedRoomsCount, String body, String roomId, String roomName, boolean shouldPlaySound, boolean isInvitationEvent) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setWhen(System.currentTimeMillis()); if (!TextUtils.isEmpty(from)) { // don't display the room name for 1:1 room notifications. if (!TextUtils.isEmpty(roomName) && !roomName.equals(from)) { builder.setContentTitle(from + " (" + roomName + ")"); } else { builder.setContentTitle(from); } } else { builder.setContentTitle(roomName); } builder.setContentText(body); builder.setAutoCancel(true); builder.setSmallIcon(R.drawable.message_notification_transparent); if (null != largeIcon) { largeIcon = createSquareBitmap(largeIcon); // add a bubble in the top right if (0 != unseenNotifiedRoomsCount) { try { android.graphics.Bitmap.Config bitmapConfig = largeIcon.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; } // setLargeIcon must used a 64 * 64 pixels bitmap // rescale to have the same text UI. float densityScale = context.getResources().getDisplayMetrics().density; int side = (int) (64 * densityScale); Bitmap bitmapCopy = Bitmap.createBitmap(side, side, bitmapConfig); Canvas canvas = new Canvas(bitmapCopy); // resize the bitmap to fill in size int bitmapWidth = largeIcon.getWidth(); int bitmapHeight = largeIcon.getHeight(); float scale = Math.min((float) canvas.getWidth() / (float) bitmapWidth, (float) canvas.getHeight() / (float) bitmapHeight); int scaledWidth = (int) (bitmapWidth * scale); int scaledHeight = (int) (bitmapHeight * scale); Bitmap rescaledBitmap = Bitmap.createScaledBitmap(largeIcon, scaledWidth, scaledHeight, true); canvas.drawBitmap(rescaledBitmap, (side - scaledWidth) / 2, (side - scaledHeight) / 2, null); String text = "" + unseenNotifiedRoomsCount; // prepare the text drawing Paint textPaint = new Paint(); textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); textPaint.setColor(Color.WHITE); textPaint.setTextSize(10 * densityScale); // get its size Rect textBounds = new Rect(); if (-1 == mUnreadBubbleWidth) { textPaint.getTextBounds("99", 0, 2, textBounds); mUnreadBubbleWidth = textBounds.width(); } textPaint.getTextBounds(text, 0, text.length(), textBounds); // draw a red circle int radius = mUnreadBubbleWidth; Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); canvas.drawCircle(canvas.getWidth() - radius, radius, radius, paint); // draw the text canvas.drawText(text, canvas.getWidth() - textBounds.width() - (radius - (textBounds.width() / 2)), -textBounds.top + (radius - (-textBounds.top / 2)), textPaint); // get the new bitmap largeIcon = bitmapCopy; } catch (Exception e) { Log.e(LOG_TAG, "## buildMessageNotification(): Exception Msg=" + e.getMessage()); } } builder.setLargeIcon(largeIcon); } String name = ": "; if (!TextUtils.isEmpty(roomName)) { name = " (" + roomName + "): "; } if (displayMatrixId) { from = "[" + matrixId + "]\n" + from; } builder.setTicker(from + name + body); TaskStackBuilder stackBuilder; Intent intent; intent = new Intent(context, VectorRoomActivity.class); intent.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomId); if (null != matrixId) { intent.putExtra(VectorRoomActivity.EXTRA_MATRIX_ID, matrixId); } stackBuilder = TaskStackBuilder.create(context).addParentStack(VectorRoomActivity.class) .addNextIntent(intent); // android 4.3 issue // use a generator for the private requestCode. // When using 0, the intent is not created/launched when the user taps on the notification. // PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000), PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); // display the message with more than 1 lines when the device supports it NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle(); textStyle.bigText(from + ":" + body); builder.setStyle(textStyle); // do not offer to quick respond if the user did not dismiss the previous one if (!LockScreenActivity.isDisplayingALockScreenActivity()) { if (!isInvitationEvent) { // offer to type a quick answer (i.e. without launching the application) Intent quickReplyIntent = new Intent(context, LockScreenActivity.class); quickReplyIntent.putExtra(LockScreenActivity.EXTRA_ROOM_ID, roomId); quickReplyIntent.putExtra(LockScreenActivity.EXTRA_SENDER_NAME, from); quickReplyIntent.putExtra(LockScreenActivity.EXTRA_MESSAGE_BODY, body); if (null != matrixId) { quickReplyIntent.putExtra(LockScreenActivity.EXTRA_MATRIX_ID, matrixId); } // the action must be unique else the parameters are ignored quickReplyIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis()))); PendingIntent pIntent = PendingIntent.getActivity(context, 0, quickReplyIntent, 0); builder.addAction(R.drawable.vector_notification_quick_reply, context.getString(R.string.action_quick_reply), pIntent); } else { { // offer to type a quick reject button Intent leaveIntent = new Intent(context, JoinScreenActivity.class); leaveIntent.putExtra(JoinScreenActivity.EXTRA_ROOM_ID, roomId); leaveIntent.putExtra(JoinScreenActivity.EXTRA_MATRIX_ID, matrixId); leaveIntent.putExtra(JoinScreenActivity.EXTRA_REJECT, true); // the action must be unique else the parameters are ignored leaveIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis()))); PendingIntent pIntent = PendingIntent.getActivity(context, 0, leaveIntent, 0); builder.addAction(R.drawable.vector_notification_reject_invitation, context.getString(R.string.reject), pIntent); } { // offer to type a quick accept button Intent acceptIntent = new Intent(context, JoinScreenActivity.class); acceptIntent.putExtra(JoinScreenActivity.EXTRA_ROOM_ID, roomId); acceptIntent.putExtra(JoinScreenActivity.EXTRA_MATRIX_ID, matrixId); acceptIntent.putExtra(JoinScreenActivity.EXTRA_JOIN, true); // the action must be unique else the parameters are ignored acceptIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis()))); PendingIntent pIntent = PendingIntent.getActivity(context, 0, acceptIntent, 0); builder.addAction(R.drawable.vector_notification_accept_invitation, context.getString(R.string.join), pIntent); } } // Build the pending intent for when the notification is clicked Intent roomIntentTap; if (isInvitationEvent) { // for invitation the room preview must be displayed roomIntentTap = CommonActivityUtils.buildIntentPreviewRoom(matrixId, roomId, context, VectorFakeRoomPreviewActivity.class); } else { roomIntentTap = new Intent(context, VectorRoomActivity.class); roomIntentTap.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomId); } // the action must be unique else the parameters are ignored roomIntentTap.setAction(TAP_TO_VIEW_ACTION + ((int) (System.currentTimeMillis()))); // Recreate the back stack TaskStackBuilder stackBuilderTap = TaskStackBuilder.create(context) .addParentStack(VectorRoomActivity.class).addNextIntent(roomIntentTap); builder.addAction(R.drawable.vector_notification_open, context.getString(R.string.action_open), stackBuilderTap.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); } //extendForCar(context, builder, roomId, roomName, from, body); Notification n = builder.build(); n.flags |= Notification.FLAG_SHOW_LIGHTS; n.defaults |= Notification.DEFAULT_LIGHTS; if (shouldPlaySound) { n.defaults |= Notification.DEFAULT_SOUND; } if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { // some devices crash if this field is not set // even if it is deprecated // setLatestEventInfo() is deprecated on Android M, so we try to use // reflection at runtime, to avoid compiler error: "Cannot resolve method.." try { Method deprecatedMethod = n.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class); deprecatedMethod.invoke(n, context, from, body, pendingIntent); } catch (Exception ex) { Log.e(LOG_TAG, "## buildMessageNotification(): Exception - setLatestEventInfo() Msg=" + ex.getMessage()); } } return n; }
From source file:com.example.psumaps.MapView.java
public static Bitmap convertToMutable(Bitmap imgIn) { try {/* ww w .ja v a 2 s . c om*/ // this is the file going to use temporally to save the bytes. // This file will not be a image, it will store the raw image data. File file = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.tmp"); // Open an RandomAccessFile // Make sure you have added uses-permission // android:name="android.permission.WRITE_EXTERNAL_STORAGE" // into AndroidManifest.xml file RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); // get the width and height of the source bitmap. int width = imgIn.getWidth(); int height = imgIn.getHeight(); Bitmap.Config type = imgIn.getConfig(); // Copy the byte to the file // Assume source bitmap loaded using options.inPreferredConfig = // Config.ARGB_8888; FileChannel channel = randomAccessFile.getChannel(); MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, 0, imgIn.getRowBytes() * height); imgIn.copyPixelsToBuffer(map); // recycle the source bitmap, this will be no longer used. imgIn.recycle(); System.gc();// try to force the bytes from the imgIn to be released // Create a new bitmap to load the bitmap again. Probably the memory // will be available. imgIn = Bitmap.createBitmap(width, height, type); map.position(0); // load it back from temporary imgIn.copyPixelsFromBuffer(map); // close the temporary file and channel , then delete that also channel.close(); randomAccessFile.close(); // delete the temp file file.delete(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return imgIn; }
From source file:com.ddoskify.CameraOverlayActivity.java
/** * Initializes the UI and initiates the creation of a face detector. *///from w w w. j a v a 2 s . c o m @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay); mFaces = new ArrayList<FaceTracker>(); final ImageButton button = (ImageButton) findViewById(R.id.flipButton); button.setOnClickListener(mFlipButtonListener); if (savedInstanceState != null) { mIsFrontFacing = savedInstanceState.getBoolean("IsFrontFacing"); } mTakePictureButton = (Button) findViewById(R.id.takePictureButton); mTakePictureButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.e("CameraOverlay", "Button has been pressed"); mCameraSource.takePicture(new CameraSource.ShutterCallback() { @Override public void onShutter() { // mCameraSource.stop(); Snackbar.make(findViewById(android.R.id.content), "Picture Taken!", Snackbar.LENGTH_SHORT) .setActionTextColor(Color.BLACK).show(); } }, new CameraSource.PictureCallback() { public void onPictureTaken(byte[] data) { int re = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE); if (!isStorageAllowed()) { requestStoragePermission(); } File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } try { Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length); Bitmap resizedBitmap = Bitmap.createBitmap(mGraphicOverlay.getWidth(), mGraphicOverlay.getHeight(), picture.getConfig()); Canvas canvas = new Canvas(resizedBitmap); Matrix matrix = new Matrix(); matrix.setScale((float) resizedBitmap.getWidth() / (float) picture.getWidth(), (float) resizedBitmap.getHeight() / (float) picture.getHeight()); if (mIsFrontFacing) { // mirror by inverting scale and translating matrix.preScale(-1, 1); matrix.postTranslate(canvas.getWidth(), 0); } Paint paint = new Paint(); canvas.drawBitmap(picture, matrix, paint); mGraphicOverlay.draw(canvas); // make those accessible FileOutputStream fos = new FileOutputStream(pictureFile); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); fos.close(); Intent intent = new Intent(getApplicationContext(), PhotoReviewActivity.class); intent.putExtra(BITMAP_MESSAGE, pictureFile.toString()); startActivity(intent); Log.d("CameraOverlay", "Starting PhotoReviewActivity " + pictureFile.toString()); } catch (FileNotFoundException e) { Log.e("CameraOverlay", e.toString()); } catch (IOException e) { Log.e("CameraOverlay", e.toString()); } } }); } }); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(); } else { requestCameraPermission(); } }
From source file:Main.java
private static Bitmap fastblur(Bitmap sentBitmap, int radius) { // Stack Blur v1.0 from // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html //// w w w .j a v a 2 s . c om // Java Author: Mario Klingemann <mario at quasimondo.com> // http://incubator.quasimondo.com // created Feburary 29, 2004 // Android port : Yahel Bouaziz <yahel at kayenko.com> // http://www.kayenko.com // ported april 5th, 2012 // This is a compromise between Gaussian Blur and Box blur // It creates much better looking blurs than Box Blur, but is // 7x faster than my Gaussian Blur implementation. // // I called it Stack Blur because this describes best how this // filter works internally: it creates a kind of moving stack // of colors whilst scanning through the image. Thereby it // just has to add one new block of color to the right side // of the stack and remove the leftmost color. The remaining // colors on the topmost layer of the stack are either added on // or reduced by one, depending on if they are on the right or // on the left side of the stack. // // If you are using this algorithm in your code please add // the following line: // // Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com> Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); if (radius < 1) { return null; } int w = bitmap.getWidth(); int h = bitmap.getHeight(); int[] pix = new int[w * h]; bitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1; int hm = h - 1; int wh = w * h; int div = radius + radius + 1; int r[] = new int[wh]; int g[] = new int[wh]; int b[] = new int[wh]; int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; int vmin[] = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1; divsum *= divsum; int dv[] = new int[256 * divsum]; for (i = 0; i < 256 * divsum; i++) { dv[i] = (i / divsum); } yw = yi = 0; int[][] stack = new int[div][3]; int stackpointer; int stackstart; int[] sir; int rbs; int r1 = radius + 1; int routsum, goutsum, boutsum; int rinsum, ginsum, binsum; for (y = 0; y < h; y++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { p = pix[yi + Math.min(wm, Math.max(i, 0))]; sir = stack[i + radius]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rbs = r1 - Math.abs(i); rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } } stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (y == 0) { vmin[x] = Math.min(x + radius + 1, wm); } p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[(stackpointer) % div]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi++; } yw += w; } for (x = 0; x < w; x++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } if (i < hm) { yp += w; } } yi = x; stackpointer = radius; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (x == 0) { vmin[y] = Math.min(y + r1, hm) * w; } p = x + vmin[y]; sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]; rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[stackpointer]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi += w; } } bitmap.setPixels(pix, 0, w, 0, 0, w, h); return (bitmap); }
From source file:github.madmarty.madsonic.util.ImageLoader.java
private void setImage(RemoteControlClient remoteControl, Drawable drawable) { if (remoteControl != null && drawable != null) { Bitmap origBitmap = ((BitmapDrawable) drawable).getBitmap(); remoteControl.editMetadata(false).putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, origBitmap.copy(origBitmap.getConfig(), true)).apply(); }/* w w w. j a v a2 s . co m*/ }