@Override public void run() { // from File try { File file = new File(getFolderNmae() + File.separator + String.valueOf(model.key.hashCode())); if (file.exists()) { Bitmap bitmap = BitmapFactory.decodeFile(file.getPath()); model.bitmap = bitmap; return; } GPUImage gpuImage = new GPUImage(mContext); gpuImage.setImage(model.bitmap); gpuImage.setFilter(model.mGPUImageFilter); Bitmap bitmap = gpuImage.getBitmapWithFilterApplied(); model.bitmap = bitmap; if (SDCardUtil.isSDCardAvaiable()) { saveBitmap( mContext, bitmap, mSaveType, getFolderNmae(), String.valueOf(model.key.hashCode()), false); } return; } catch (Exception e) { e.printStackTrace(); } finally { imageCache.put(model.key, new SoftReference<Bitmap>(model.bitmap)); Message msg = Message.obtain(); msg.what = HANDLER_SEND_CODE; msg.obj = model; mHandler.sendMessage(msg); } }
// ギャラリー、カメラから戻ってきたときの処理をする関数 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Bitmap bm = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; // 元の1/4サイズでbitmap取得 switch (requestCode) { case REQUEST_CAMERA: System.out.println(bitmapUri.getPath()); bm = BitmapFactory.decodeFile(bitmapUri.getPath(), options); // 撮影した画像をギャラリーのインデックスに追加されるようにスキャンする。 // これをやらないと、アプリ起動中に撮った写真が反映されない String[] paths = {bitmapUri.getPath()}; String[] mimeTypes = {"image/*"}; MediaScannerConnection.scanFile( getApplicationContext(), paths, mimeTypes, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) {} }); break; case REQUEST_GALLERY: try { if (data != null || data.getData() != null) { bitmapUri = data.getData(); InputStream is = getContentResolver().openInputStream(data.getData()); bm = BitmapFactory.decodeStream(is, null, options); is.close(); } } catch (OutOfMemoryError e) { e.printStackTrace(); bm = null; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } break; default: finish(); break; } ExifInterface exif = null; try { exif = new ExifInterface(bitmapUri.getPath()); } catch (IOException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } Matrix matrix = new Matrix(); if (exif != null) { int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (orientation == 6) { matrix.postRotate(90); } else if (orientation == 3) { matrix.postRotate(180); } else if (orientation == 8) { matrix.postRotate(270); } } bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); gpuImage.setImage(bm); imageView.setImageBitmap(bm); } else { finish(); } }
@Override protected void onPostExecute(Bitmap bitmap) { super.onPostExecute(bitmap); mGPUImage.deleteImage(); mGPUImage.setImage(bitmap); }
/** * Sets the image on which the filter should be applied. * * @param bitmap the new image */ public void setImage(final Bitmap bitmap) { setImage(bitmap, false); mCurrentBitmap = bitmap; }
/** * Sets the image on which the filter should be applied from a File. * * @param file the file of the new image */ public void setImage(final File file) { mGPUImage.setImage(file); }
/** * Sets the image on which the filter should be applied from a Uri. * * @param uri the uri of the new image */ public void setImage(final Uri uri) { mGPUImage.setImage(uri); }
/** * Sets the image on which the filter should be applied. * * @param bitmap the new image */ public void setImage(final Bitmap bitmap) { mGPUImage.setImage(bitmap); }