android.graphics.BitmapFactory Java Examples
The following examples show how to use
android.graphics.BitmapFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BitmapConvert.java From DoraemonKit with Apache License 2.0 | 7 votes |
private Bitmap parse(byte[] byteArray) throws OutOfMemoryError { BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); Bitmap bitmap; if (maxWidth == 0 && maxHeight == 0) { decodeOptions.inPreferredConfig = decodeConfig; bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, decodeOptions); } else { decodeOptions.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, decodeOptions); int actualWidth = decodeOptions.outWidth; int actualHeight = decodeOptions.outHeight; int desiredWidth = getResizedDimension(maxWidth, maxHeight, actualWidth, actualHeight, scaleType); int desiredHeight = getResizedDimension(maxHeight, maxWidth, actualHeight, actualWidth, scaleType); decodeOptions.inJustDecodeBounds = false; decodeOptions.inSampleSize = findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight); Bitmap tempBitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, decodeOptions); if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth || tempBitmap.getHeight() > desiredHeight)) { bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth, desiredHeight, true); tempBitmap.recycle(); } else { bitmap = tempBitmap; } } return bitmap; }
Example #2
Source File: BitmapWorkerTask.java From WebCachedImageView with BSD 2-Clause "Simplified" License | 6 votes |
private static Bitmap decodeSampledBitmapFromUrl(String url, int reqWidth, int reqHeight) throws IOException { // First decode with inJustDecodeBounds=true to check dimensions final Options options = new Options(); options.inJustDecodeBounds = true; InputStream stream = fetchStream(url); BitmapFactory.decodeStream(stream, null, options); stream.close(); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; stream = fetchStream(url); Bitmap bitmap = BitmapFactory.decodeStream(stream, null, options); stream.close(); return bitmap; }
Example #3
Source File: IconDialog.java From NanoIconPack with Apache License 2.0 | 6 votes |
private void returnPickIcon() { Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeResource(getResources(), iconBean.getId()); } catch (Exception e) { e.printStackTrace(); } Intent intent = new Intent(); if (bitmap != null) { intent.putExtra("icon", bitmap); intent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", iconBean.getId()); intent.setData(Uri.parse("android.resource://" + getContext().getPackageName() + "/" + String.valueOf(iconBean.getId()))); getActivity().setResult(Activity.RESULT_OK, intent); } else { getActivity().setResult(Activity.RESULT_CANCELED, intent); } getActivity().finish(); }
Example #4
Source File: GlideBitmapFactory.java From GlideBitmapPool with Apache License 2.0 | 6 votes |
public static Bitmap decodeFile(String pathName, int reqWidth, int reqHeight) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(pathName, options); options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { options.inMutable = true; Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig); if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) { options.inBitmap = inBitmap; } } options.inJustDecodeBounds = false; try { return BitmapFactory.decodeFile(pathName, options); } catch (Exception e) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { options.inBitmap = null; } return BitmapFactory.decodeFile(pathName, options); } }
Example #5
Source File: ImageLoader.java From Yahala-Messenger with MIT License | 6 votes |
/** * Decode and sample down a bitmap from a file input stream to the requested width and height. * * @param fileDescriptor The file descriptor to read from * @param reqWidth The requested width of the resulting bitmap * @param reqHeight The requested height of the resulting bitmap * @return A bitmap sampled down from the original with the same aspect ratio and dimensions * that are equal to or greater than the requested width and height */ public static Bitmap decodeSampledBitmapFromDescriptor( FileDescriptor fileDescriptor, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); }
Example #6
Source File: FaceCategroyAdapter.java From EmojiChat with Apache License 2.0 | 6 votes |
@Override public void setPageIcon(int position, ImageView image) { if (position == 0) { image.setImageResource(R.drawable.icon_face_click); return; } File file = new File(datas.get(position - 1)); String path = null; for (int i = 0; i < file.list().length; i++) { path = file.list()[i]; if (path.endsWith(".png") || path.endsWith(".jpg") || path.endsWith(".jpeg")) { break; } } Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath() + "/" + path); image.setImageBitmap(bitmap); }
Example #7
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 6 votes |
private void loadPhotoSphere() { //This could take a while. Should do on a background thread, but fine for current example VrPanoramaView.Options options = new VrPanoramaView.Options(); InputStream inputStream = null; AssetManager assetManager = getAssets(); try { inputStream = assetManager.open("openspace.jpg"); options.inputType = VrPanoramaView.Options.TYPE_MONO; mVrPanoramaView.loadImageFromBitmap(BitmapFactory.decodeStream(inputStream), options); inputStream.close(); } catch (IOException e) { Log.e("Tuts+", "Exception in loadPhotoSphere: " + e.getMessage() ); } }
Example #8
Source File: FavoritesListAdapter.java From arcusandroid with Apache License 2.0 | 6 votes |
public void bind(@NonNull FavoriteItemModel favoriteItemModel) { mTextView.setText(favoriteItemModel.getTitle()); mTextView.setAlpha(favoriteItemModel.isDisabled() ? 0.4f : 1.0f); if (favoriteItemModel.getImageResource() != null) { BlackWhiteInvertTransformation transform = new BlackWhiteInvertTransformation(Invert.BLACK_TO_WHITE); Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), favoriteItemModel.getImageResource()); if(favoriteItemModel.getKeepImageColor()) { mImageView.setImageBitmap(bitmap); } else { mImageView.setImageBitmap(transform.transform(bitmap)); } } else { ImageManager.with(mContext) .putSmallDeviceImage((DeviceModel) favoriteItemModel.getModel()) .withTransformForStockImages(new BlackWhiteInvertTransformation(Invert.BLACK_TO_WHITE)) .withPlaceholder(R.drawable.device_list_placeholder) .withError(R.drawable.device_list_placeholder) .noUserGeneratedImagery() .into(mImageView) .execute(); } mImageView.setAlpha(favoriteItemModel.isDisabled() ? 0.4f : 1.0f); }
Example #9
Source File: MainActivity.java From BooheeScrollView with MIT License | 6 votes |
public static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { // Calculate ratios of height and width to requested height and width final int heightRatio = Math.round((float) height / (float) reqHeight); final int widthRatio = Math.round((float) width / (float) reqWidth); // Choose the smallest ratio as inSampleSize value, this will guarantee // a final image with both dimensions larger than or equal to the // requested height and width. inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } return inSampleSize; }
Example #10
Source File: FollowList.java From AndroidLinkup with GNU General Public License v2.0 | 6 votes |
public FollowAdapter(PullToRefreshView view) { super(view); curPage = -1; hasNext = true; map = new HashMap<String, Following>(); follows = new ArrayList<Following>(); llHeader = new PRTHeader(getContext()); int resId = getBitmapRes(getContext(), "auth_follow_cb_chd"); if (resId > 0) { bmChd = BitmapFactory.decodeResource(view.getResources(), resId); } resId = getBitmapRes(getContext(), "auth_follow_cb_unc"); if (resId > 0) { bmUnch = BitmapFactory.decodeResource(view.getResources(), resId); } }
Example #11
Source File: STUtils.java From Fatigue-Detection with MIT License | 6 votes |
@SuppressLint("NewApi") public static Bitmap NV21ToRGBABitmap(byte []nv21, int width, int height, Context context) { TimingLogger timings = new TimingLogger(TIMING_LOG_TAG, "NV21ToRGBABitmap"); Rect rect = new Rect(0, 0, width, height); try { Class.forName("android.renderscript.Element$DataKind").getField("PIXEL_YUV"); Class.forName("android.renderscript.ScriptIntrinsicYuvToRGB"); byte[] imageData = nv21; if (mRS == null) { mRS = RenderScript.create(context); mYuvToRgb = ScriptIntrinsicYuvToRGB.create(mRS, Element.U8_4(mRS)); Type.Builder tb = new Type.Builder(mRS, Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV)); tb.setX(width); tb.setY(height); tb.setMipmaps(false); tb.setYuvFormat(ImageFormat.NV21); ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT); timings.addSplit("Prepare for ain"); Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS)); tb2.setX(width); tb2.setY(height); tb2.setMipmaps(false); aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_SCRIPT & Allocation.USAGE_SHARED); timings.addSplit("Prepare for aOut"); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); timings.addSplit("Create Bitmap"); } ain.copyFrom(imageData); timings.addSplit("ain copyFrom"); mYuvToRgb.setInput(ain); timings.addSplit("setInput ain"); mYuvToRgb.forEach(aOut); timings.addSplit("NV21 to ARGB forEach"); aOut.copyTo(bitmap); timings.addSplit("Allocation to Bitmap"); } catch (Exception e) { YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, width, height, null); timings.addSplit("NV21 bytes to YuvImage"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); yuvImage.compressToJpeg(rect, 90, baos); byte[] cur = baos.toByteArray(); timings.addSplit("YuvImage crop and compress to Jpeg Bytes"); bitmap = BitmapFactory.decodeByteArray(cur, 0, cur.length); timings.addSplit("Jpeg Bytes to Bitmap"); } timings.dumpToLog(); return bitmap; }
Example #12
Source File: BitmapUtils.java From ToolsFinal with Apache License 2.0 | 6 votes |
/** * 压缩bitmp到目标大小(质量压缩) * @param bitmap * @param needRecycle * @param maxSize * @return */ public static Bitmap compressBitmap(Bitmap bitmap, boolean needRecycle, long maxSize) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); int options = 100; while (baos.toByteArray().length > maxSize) { baos.reset();//重置baos即清空baos bitmap.compress(Bitmap.CompressFormat.JPEG, options, baos); options -= 10;//每次都减少10 } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); Bitmap bm = BitmapFactory.decodeStream(isBm, null, null); if(needRecycle) { bitmap.recycle(); } bitmap = bm; return bitmap; }
Example #13
Source File: PrintHelperKitkat.java From adt-leanback-support with Apache License 2.0 | 6 votes |
/** * Returns the bitmap from the given uri loaded using the given options. * Returns null on failure. */ private Bitmap loadBitmap(Uri uri, BitmapFactory.Options o) throws FileNotFoundException { if (uri == null || mContext == null) { throw new IllegalArgumentException("bad argument to loadBitmap"); } InputStream is = null; try { is = mContext.getContentResolver().openInputStream(uri); return BitmapFactory.decodeStream(is, null, o); } finally { if (is != null) { try { is.close(); } catch (IOException t) { Log.w(LOG_TAG, "close fail ", t); } } } }
Example #14
Source File: PublishActivity.java From styT with Apache License 2.0 | 6 votes |
/** * 压缩指定路径的图片,并得到图片对象 * * @param path * @return */ private Bitmap compressBitmapFromFile(String path) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(path, options); options.inJustDecodeBounds = false; int width = options.outWidth; int height = options.outHeight; float widthRadio = 1080f; float heightRadio = 1920f; int inSampleSize = 1; if (width > height && width > widthRadio) { inSampleSize = (int) (width * 1.0f / widthRadio); } else if (width < height && height > heightRadio) { inSampleSize = (int) (height * 1.0f / heightRadio); } if (inSampleSize <= 0) { inSampleSize = 1; } options.inSampleSize = inSampleSize; bitmap = BitmapFactory.decodeFile(path, options); return compressBitmap(bitmap); }
Example #15
Source File: MorphingFragment.java From droid-stealth with GNU General Public License v2.0 | 6 votes |
/** * Loads a Bitmap from the given URI and scales and crops it to the given size * * @param uri The URI to load the Bitmap from * @param size The size the final Bitmap should be * @return */ private Bitmap loadCroppedBitmapFromUri(Uri uri, int size) { File bitmapFile = FileUtils.getFile(getActivity(), uri); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(bitmapFile.getPath(), options); // TODO: Handle null pointers. options.inSampleSize = calculateSampleSize(options, size, size); options.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeFile(bitmapFile.getPath(), options); if (bitmap == null) { Utils.d("Bitmap loading failed!"); return null; } if (bitmap.getHeight() > size || bitmap.getWidth() > size) { bitmap = Utils.crop(bitmap, size, size); } return bitmap; }
Example #16
Source File: FragmentSelect.java From imageres_resolution with MIT License | 6 votes |
private boolean verifyImage(Uri uri) { InputStream inputStream; try { inputStream = getActivity().getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(inputStream, null, options); if (options.outWidth > MAX_IAMGE_SIZE || options.outHeight > MAX_IAMGE_SIZE) return false; return true; }
Example #17
Source File: Bitmaps.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) { Bitmap bitmap; if (Build.VERSION.SDK_INT < 21) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inDither = true; options.inPreferredConfig = config; options.inPurgeable = true; options.inSampleSize = 1; options.inMutable = true; byte[] array = jpegData.get(); array[76] = (byte) (height >> 8); array[77] = (byte) (height & 0x00ff); array[78] = (byte) (width >> 8); array[79] = (byte) (width & 0x00ff); bitmap = BitmapFactory.decodeByteArray(array, 0, array.length, options); Utilities.pinBitmap(bitmap); bitmap.setHasAlpha(true); bitmap.eraseColor(0); } else { bitmap = Bitmap.createBitmap(width, height, config); } if (config == Bitmap.Config.ARGB_8888 || config == Bitmap.Config.ARGB_4444) { bitmap.eraseColor(Color.TRANSPARENT); } return bitmap; }
Example #18
Source File: ImageActivity.java From retroboy with MIT License | 6 votes |
@Override protected void onPostExecute(File result) { // Remember the written file in case the filter or contrast is changed _outputpath = result.toString(); // Show the processed image Bitmap bm = BitmapFactory.decodeFile(result.toString()); if (bm != null) { _imageview.setImageBitmap(bm); } else { Log.w(TAG, "Failed to read created image " + result.toString()); } if (_task == this) { _task = null; } super.onPostExecute(result); }
Example #19
Source File: RotaryView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
public void Init() { dp = getResources().getDimension(R.dimen.triangle_dp); bitmapScale = BitmapFactory.decodeResource(getResources(), R.drawable.triangle_icon_round_calibration); brWidth = bitmapScale.getWidth(); brHeight = bitmapScale.getHeight(); WidthCenter = getWidth() / 2; HeightCenter = getHeight() / 2; zoom(0f); rectf = new RectF(); rectf.set(dp * 0.1f, dp * 0.1f, getWidth() - dp * 0.1f, getHeight() - dp * 0.1f); }
Example #20
Source File: WXHelper.java From SocialHelper with Apache License 2.0 | 6 votes |
private boolean addTitleSummaryAndThumb(WXMediaMessage msg, Bundle params) { if (params.containsKey(WXShareEntity.KEY_WX_TITLE)) { msg.title = params.getString(WXShareEntity.KEY_WX_TITLE); } if (params.containsKey(WXShareEntity.KEY_WX_SUMMARY)) { msg.description = params.getString(WXShareEntity.KEY_WX_SUMMARY); } if (params.containsKey(WXShareEntity.KEY_WX_IMG_LOCAL) || params.containsKey(WXShareEntity.KEY_WX_IMG_RES)) { Bitmap bitmap; if (params.containsKey(WXShareEntity.KEY_WX_IMG_LOCAL)) {//分为本地文件和应用内资源图片 String imgUrl = params.getString(WXShareEntity.KEY_WX_IMG_LOCAL); if (notFoundFile(imgUrl)) { return true; } bitmap = BitmapFactory.decodeFile(imgUrl); } else { bitmap = BitmapFactory.decodeResource(activity.getResources(), params.getInt(WXShareEntity.KEY_WX_IMG_RES)); } msg.thumbData = SocialUtil.bmpToByteArray(bitmap, true); } return false; }
Example #21
Source File: MediaService.java From AndroidDemo with MIT License | 5 votes |
private void sendCustomerNotification(int command){ NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("Notification"); builder.setContentText("自定义通知栏示例"); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.push)); builder.setAutoCancel(false); builder.setOngoing(true); builder.setShowWhen(false); RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.notification_template_customer); remoteViews.setTextViewText(R.id.title,"音乐播放器"); remoteViews.setTextViewText(R.id.text,"歌曲"+index); if(command==CommandNext){ remoteViews.setImageViewResource(R.id.btn1,R.drawable.ic_pause_white); }else if(command==CommandPlay){ if(playerStatus==StatusStop){ remoteViews.setImageViewResource(R.id.btn1,R.drawable.ic_pause_white); }else{ remoteViews.setImageViewResource(R.id.btn1,R.drawable.ic_play_arrow_white_18dp); } } Intent Intent1 = new Intent(this,MediaService.class); Intent1.putExtra("command",CommandPlay); PendingIntent PIntent1 = PendingIntent.getService(this,5,Intent1,0); remoteViews.setOnClickPendingIntent(R.id.btn1,PIntent1); Intent Intent2 = new Intent(this,MediaService.class); Intent2.putExtra("command",CommandNext); PendingIntent PIntent2 = PendingIntent.getService(this,6,Intent2,0); remoteViews.setOnClickPendingIntent(R.id.btn2,PIntent2); Intent Intent3 = new Intent(this,MediaService.class); Intent3.putExtra("command",CommandClose); PendingIntent PIntent3 = PendingIntent.getService(this,7,Intent3,0); remoteViews.setOnClickPendingIntent(R.id.btn3,PIntent3); builder.setContent(remoteViews); Notification notification = builder.build(); manger.notify(MainActivity.TYPE_Customer,notification); }
Example #22
Source File: UGCImageIntentResultHandler.java From arcusandroid with Apache License 2.0 | 5 votes |
public static Bitmap loadScaledBitmapFromFile(String file, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(file, options); // Calculate inSampleSize options.inSampleSize = calculateImageSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(file, options); }
Example #23
Source File: CompressImageUtil.java From TakePhoto with Apache License 2.0 | 5 votes |
public void compress(String imagePath, CompressListener listener) { if (config.isEnablePixelCompress()) { try { compressImageByPixel(imagePath, listener); } catch (FileNotFoundException e) { listener.onCompressFailed(imagePath, String.format("图片压缩失败,%s", e.toString())); e.printStackTrace(); } } else { compressImageByQuality(BitmapFactory.decodeFile(imagePath), imagePath, listener); } }
Example #24
Source File: DefaultImageGetter.java From Ruisi with Apache License 2.0 | 5 votes |
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth) { // 源图片的高度和宽度 final int width = options.outWidth; int inSampleSize = 1; if (width > reqWidth) { final int halfWidth = width / 2; while ((halfWidth / inSampleSize) >= reqWidth) { inSampleSize *= 2; } } return inSampleSize; }
Example #25
Source File: BInstallerView.java From brouter with MIT License | 5 votes |
public void startInstaller() { baseDir = ConfigHelper.getBaseDir( getContext() ); try { AssetManager assetManager = getContext().getAssets(); InputStream istr = assetManager.open("world.png"); bmp = BitmapFactory.decodeStream(istr); istr.close(); } catch( IOException io ) { throw new RuntimeException( "cannot read world.png from assets" ); } tileStatus = new int[72*36]; scanExistingFiles(); float scaleX = imgwOrig / ((float)bmp.getWidth()); float scaley = imghOrig / ((float)bmp.getHeight()); viewscale = scaleX < scaley ? scaleX : scaley; mat = new Matrix(); mat.postScale( viewscale, viewscale ); tilesVisible = false; }
Example #26
Source File: CropImageView.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public void setImageResource(int i1) { if (i1 != 0) { setImageBitmap(BitmapFactory.decodeResource(getResources(), i1)); } }
Example #27
Source File: ImageLoader.java From imageCrop with MIT License | 5 votes |
/** * Loads a bitmap that has been downsampled using sampleSize from a given url. */ public static Bitmap loadDownsampledBitmap(Context context, Uri uri, int sampleSize) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inMutable = true; options.inSampleSize = sampleSize; return loadBitmap(context, uri, options); }
Example #28
Source File: FullScreenImageViewerActivity.java From FreezeYou with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { ThemeUtils.processSetTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.fsiva_main); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); } Intent intent = getIntent(); if (intent != null) { ImageView fsiva_main_imageView = findViewById(R.id.fsiva_main_imageView); fsiva_main_imageView.setImageBitmap( BitmapFactory.decodeFile(intent.getStringExtra("imgPath")) ); fsiva_main_imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } else { finish(); } }
Example #29
Source File: Utils.java From coloring with GNU General Public License v3.0 | 5 votes |
/** * Loads a Bitmap from a stream, given an InputStreamProvider. * * See also https://developer.android.com/topic/performance/graphics/load-bitmap.html#load-bitmap * * @param requiredWidth * @param requiredHeight * @return */ public static Bitmap decodeSampledBitmapFromStream(InputStreamProvider inputStreamProvider, int requiredWidth, int requiredHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(inputStreamProvider.getStream(), null, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options.outWidth, options.outHeight, requiredWidth, requiredHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeStream(inputStreamProvider.getStream(), null, options); }
Example #30
Source File: GameActivity.java From SchoolQuest with GNU General Public License v3.0 | 5 votes |
public void runningShoes(boolean equip) { ImageView runButton = findViewById(R.id.run_button); if (equip) { GAME.getPlayer().setSpeed(4); runButton.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable._ui_main_walk_button)); } else { GAME.getPlayer().setSpeed(2); runButton.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable._ui_main_run_button)); } }