Java Code Examples for android.graphics.BitmapFactory
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/util/bitmap/.
Source file: BitmapTransformer.java

public Uploadable readScaledBitmap(String path){ BitmapFactory.Options options=getBitmapSize(path); int size=calculateScale(options); options=new BitmapFactory.Options(); options.inSampleSize=size; Bitmap bitmap=BitmapFactory.decodeFile(path,options); byte[] bytes=toBytes(bitmap); bitmap.recycle(); return new Uploadable(path,bytes); }
Example 2
From project AChartEngine, under directory /achartengine/src/org/achartengine/.
Source file: GraphicalView.java

/** * Creates a new graphical view. * @param context the context * @param chart the chart to be drawn */ public void setup(Context context){ AbstractChart chart=buildChart(); mChart=chart; mHandler=new Handler(); if (mChart instanceof XYChart) { mRenderer=((XYChart)mChart).getRenderer(); } else { mRenderer=((RoundChart)mChart).getRenderer(); } if (mRenderer.isZoomButtonsVisible()) { zoomInImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_in.png")); zoomOutImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_out.png")); fitZoomImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom-1.png")); } if (mRenderer instanceof XYMultipleSeriesRenderer && ((XYMultipleSeriesRenderer)mRenderer).getMarginsColor() == XYMultipleSeriesRenderer.NO_COLOR) { ((XYMultipleSeriesRenderer)mRenderer).setMarginsColor(mPaint.getColor()); } if (mRenderer.isZoomEnabled() && mRenderer.isZoomButtonsVisible() || mRenderer.isExternalZoomEnabled()) { mZoomIn=new Zoom(mChart,true,mRenderer.getZoomRate()); mZoomOut=new Zoom(mChart,false,mRenderer.getZoomRate()); mFitZoom=new FitZoom(mChart); } int version=7; try { version=Integer.valueOf(Build.VERSION.SDK); } catch ( Exception e) { } if (version < 7) { mTouchHandler=new TouchHandlerOld(this,mChart); } else { mTouchHandler=new TouchHandler(this,mChart); } }
Example 3
From project Airports, under directory /src/com/nadmm/airports/.
Source file: ImageViewActivity.java

@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){ ImageZoomView view=new ImageZoomView(getActivity(),null); view.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); Bundle args=getArguments(); String path=args.getString(IMAGE_PATH); view.setImage(BitmapFactory.decodeFile(path)); return view; }
Example 4
From project Alerte-voirie-android, under directory /src/com/c4mprod/utils/.
Source file: ImageDownloader.java

/** * @param url The URL of the image that will be retrieved from the cache. * @return The cached bitmap or null if it was not found. */ private Bitmap getBitmapFromCache(String url){ if (mExternalStorageAvailable && url != null) { File f=new File(mfolder,URLEncoder.encode(url)); if (f.exists()) { try { return BitmapFactory.decodeFile(f.getPath()); } catch ( Exception e) { e.printStackTrace(); } } } synchronized (sHardBitmapCache) { final Bitmap bitmap=sHardBitmapCache.get(url); if (bitmap != null) { sHardBitmapCache.remove(url); sHardBitmapCache.put(url,bitmap); return bitmap; } } try { SoftReference<Bitmap> bitmapReference=sSoftBitmapCache.get(url); if (bitmapReference != null) { final Bitmap bitmap=bitmapReference.get(); if (bitmap != null) { return bitmap; } else { sSoftBitmapCache.remove(url); } } } catch ( Exception e) { return null; } return null; }
Example 5
From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/.
Source file: DisputeActivity.java

public void onResume(){ super.onResume(); ImageView preview=(ImageView)findViewById(R.id.photo_preview); if (hasPhoto) { preview.setVisibility(View.VISIBLE); Bitmap bMap=BitmapFactory.decodeFile(MakeStatementActivity.TMP_IMAGE_PATH); preview.setImageBitmap(bMap); } else { preview.setVisibility(View.GONE); } }
Example 6
From project andlytics, under directory /src/com/github/andlyticsproject/.
Source file: BaseDetailsActivity.java

@Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); getSupportActionBar().setDisplayHomeAsUpEnabled(true); String appName=getDbAdapter().getAppName(packageName); if (appName != null) { getSupportActionBar().setSubtitle(appName); } if (iconFilePath != null) { Bitmap bm=BitmapFactory.decodeFile(iconFilePath); BitmapDrawable icon=new BitmapDrawable(getResources(),bm); getSupportActionBar().setIcon(icon); } }
Example 7
From project Android, under directory /app/src/main/java/com/github/mobile/util/.
Source file: ImageUtils.java

/** * Get a bitmap from the image path * @param imagePath * @param sampleSize * @return bitmap or null if read fails */ public static Bitmap getBitmap(final String imagePath,int sampleSize){ final Options options=new Options(); options.inDither=false; options.inSampleSize=sampleSize; RandomAccessFile file=null; try { file=new RandomAccessFile(imagePath,"r"); return BitmapFactory.decodeFileDescriptor(file.getFD(),null,options); } catch ( IOException e) { Log.d(TAG,e.getMessage(),e); return null; } finally { if (file != null) try { file.close(); } catch ( IOException e) { Log.d(TAG,e.getMessage(),e); } } }
Example 8
From project android-api-demos, under directory /src/com/mobeelizer/demos/activities/.
Source file: ConflictsActivity.java

/** * Shows or hides conflicts warning text below the list view and above add/sync buttons. It should be visible only when at least one field is in conflict. * @param isVisible Whether warning should be visible. */ private void showWarning(final boolean isVisible){ mWarningText.setVisibility(isVisible ? View.VISIBLE : View.GONE); StyleSpan boldSpan=new StyleSpan(Typeface.BOLD); String text=mWarningText.getText().toString(); if (text.contains("|")) { SpannableStringBuilder ssb=new SpannableStringBuilder(text); ssb.setSpan(boldSpan,0,text.indexOf(':'),Spannable.SPAN_INCLUSIVE_INCLUSIVE); Bitmap syncIcon=BitmapFactory.decodeResource(getResources(),R.drawable.ic_sync); int syncIndex=text.indexOf('|'); ssb.setSpan(new ImageSpan(syncIcon),syncIndex,syncIndex + 1,Spannable.SPAN_INCLUSIVE_INCLUSIVE); mWarningText.setText(ssb,BufferType.SPANNABLE); } }
Example 9
From project android-bankdroid, under directory /src/com/liato/bankdroid/liveview/.
Source file: PluginUtils.java

/** * Stores icon to phone file system * @param resources Reference to project resources * @param resource Reference to specific resource * @param fileName The icon file name */ public static String storeIconToFile(Context ctx,Resources resources,int resource,String fileName){ Log.d(PluginConstants.LOG_TAG,"Store icon to file."); if (resources == null) { return ""; } Bitmap bitmap=BitmapFactory.decodeStream(resources.openRawResource(resource)); try { FileOutputStream fos=ctx.openFileOutput(fileName,Context.MODE_WORLD_READABLE); bitmap.compress(Bitmap.CompressFormat.PNG,100,fos); fos.flush(); fos.close(); } catch ( IOException e) { Log.e(PluginConstants.LOG_TAG,"Failed to store to device",e); } File iconFile=ctx.getFileStreamPath(fileName); Log.d(PluginConstants.LOG_TAG,"Icon stored. " + iconFile.getAbsolutePath()); return iconFile.getAbsolutePath(); }
Example 10
From project android-cropimage, under directory /src/com/android/camera/.
Source file: BitmapManager.java

public Bitmap getThumbnail(ContentResolver cr,long origId,int kind,BitmapFactory.Options options,boolean isVideo){ Thread t=Thread.currentThread(); ThreadStatus status=getOrCreateThreadStatus(t); if (!canThreadDecoding(t)) { Log.d(TAG,"Thread " + t + " is not allowed to decode."); return null; } try { synchronized (status) { status.mThumbRequesting=true; } if (isVideo) { return Video.Thumbnails.getThumbnail(cr,t.getId(),kind,null); } else { return Images.Thumbnails.getThumbnail(cr,t.getId(),kind,null); } } finally { synchronized (status) { status.mThumbRequesting=false; status.notifyAll(); } } }
Example 11
From project Android-File-Manager, under directory /src/com/nexes/manager/.
Source file: ThumbnailCreator.java

@Override public void run(){ int len=mFiles.size(); for (int i=0; i < len; i++) { if (mStop) { mStop=false; mFiles=null; return; } final File file=new File(mDir + "/" + mFiles.get(i)); if (isImageFile(file.getName())) { long len_kb=file.length() / 1024; BitmapFactory.Options options=new BitmapFactory.Options(); options.outWidth=mWidth; options.outHeight=mHeight; if (len_kb > 1000 && len_kb < 5000) { options.inSampleSize=32; options.inPurgeable=true; mThumb=new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(),options)); } else if (len_kb >= 5000) { options.inSampleSize=32; options.inPurgeable=true; mThumb=new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(),options)); } else if (len_kb <= 1000) { options.inPurgeable=true; mThumb=new SoftReference<Bitmap>(Bitmap.createScaledBitmap(BitmapFactory.decodeFile(file.getPath()),mWidth,mHeight,false)); } mCacheMap.put(file.getPath(),mThumb.get()); mHandler.post(new Runnable(){ @Override public void run(){ Message msg=mHandler.obtainMessage(); msg.obj=(Bitmap)mThumb.get(); msg.sendToTarget(); } } ); } } }
Example 12
From project android-flip, under directory /FlipView/FlipLibrary/src/com/aphidmobile/utils/.
Source file: IO.java

public static Bitmap readBitmap(InputStream input){ if (input == null) return null; try { return BitmapFactory.decodeStream(input); } catch ( Exception e) { AphidLog.e(e,"Failed to read bitmap"); return null; } finally { close(input); } }
Example 13
From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/helpers/.
Source file: ImageHelper.java

public static Bitmap getGifThumbnail(String originalPath,boolean createIfMissing){ String thumbPath=generateGifThumbPath(originalPath); File thumbFile=new File(thumbPath); if (!thumbFile.exists() && createIfMissing) { createGifThumbnail(originalPath); } if (!thumbFile.exists()) return null; return BitmapFactory.decodeFile(thumbPath); }
Example 14
From project android-gltron, under directory /GlTron/src/com/glTron/Video/.
Source file: GLTexture.java

private void loadTexture(GL10 gl,Context context,int resource){ gl.glGenTextures(1,_texID,0); Matrix flip=new Matrix(); flip.postScale(1f,-1f); BitmapFactory.Options opts=new BitmapFactory.Options(); opts.inScaled=false; Bitmap temp=BitmapFactory.decodeResource(context.getResources(),resource,opts); Bitmap bmp=Bitmap.createBitmap(temp,0,0,temp.getWidth(),temp.getHeight(),flip,true); temp.recycle(); gl.glBindTexture(GL10.GL_TEXTURE_2D,_texID[0]); if (boGenMipMap) { gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR_MIPMAP_NEAREST); gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR_MIPMAP_NEAREST); } else { gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR); } gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_WRAP_S,WrapS); gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_WRAP_T,WrapT); DebugType=GLUtils.getInternalFormat(bmp); if (boGenMipMap) { for (int level=0, height=bmp.getHeight(), width=bmp.getWidth(); true; level++) { GLUtils.texImage2D(GL10.GL_TEXTURE_2D,level,bmp,0); if (height == 1 && width == 1) break; width>>=1; height>>=1; if (width < 1) width=1; if (height < 1) height=1; Bitmap bmp2=Bitmap.createScaledBitmap(bmp,width,height,true); bmp.recycle(); bmp=bmp2; } } else { GLUtils.texImage2D(GL10.GL_TEXTURE_2D,0,bmp,0); } bmp.recycle(); }
Example 15
From project android-joedayz, under directory /Proyectos/androidMDWCompleto/src/com/android/mdw/demo/.
Source file: Main.java

@Override public boolean draw(Canvas canvas,MapView mapView,boolean shadow,long when){ super.draw(canvas,mapView,shadow); Point scrnPoint=new Point(); mapView.getProjection().toPixels(this.point,scrnPoint); Bitmap marker=BitmapFactory.decodeResource(getResources(),R.drawable.icon); canvas.drawBitmap(marker,scrnPoint.x - marker.getWidth() / 2,scrnPoint.y - marker.getHeight() / 2,null); return true; }
Example 16
From project Android-MapForgeFragment, under directory /library-common/src/com/jakewharton/android/mapsforge_fragment/.
Source file: TileDownloadMapGenerator.java

@Override final boolean executeJob(MapGeneratorJob mapGeneratorJob){ try { getTilePath(mapGeneratorJob.tile,this.stringBuilder); InputStream inputStream=new URL(this.stringBuilder.toString()).openStream(); this.decodedBitmap=BitmapFactory.decodeStream(inputStream); inputStream.close(); if (this.decodedBitmap == null) { return false; } this.decodedBitmap.getPixels(this.pixelColors,0,Tile.TILE_SIZE,0,0,Tile.TILE_SIZE,Tile.TILE_SIZE); this.decodedBitmap.recycle(); if (this.tileBitmap != null) { this.tileBitmap.setPixels(this.pixelColors,0,Tile.TILE_SIZE,0,0,Tile.TILE_SIZE,Tile.TILE_SIZE); } return true; } catch ( UnknownHostException e) { Logger.debug(e.getMessage()); return false; } catch ( IOException e) { Logger.exception(e); return false; } }
Example 17
From project android-mapviewballoons, under directory /android-mapviewballoons-example/src/mapviewballoons/example/custom/.
Source file: CustomBalloonOverlayView.java

@Override protected Bitmap doInBackground(String... arg0){ Bitmap b=null; try { b=BitmapFactory.decodeStream((InputStream)new URL(arg0[0]).getContent()); } catch ( MalformedURLException e) { e.printStackTrace(); } catch ( IOException e) { e.printStackTrace(); } return b; }
Example 18
From project Android-Terminal-Emulator, under directory /libraries/emulatorview/src/jackpal/androidterm/emulatorview/.
Source file: Bitmap4x8FontRenderer.java

public Bitmap4x8FontRenderer(Resources resources,ColorScheme scheme){ super(scheme); int fontResource=AndroidCompat.SDK <= 3 ? R.drawable.atari_small : R.drawable.atari_small_nodpi; mFont=BitmapFactory.decodeResource(resources,fontResource); mPaint=new Paint(); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); }
Example 19
From project android-wheel, under directory /wheel-demo/src/kankan/wheel/demo/.
Source file: SlotMachineActivity.java

/** * Loads image from resources */ private Bitmap loadImage(int id){ Bitmap bitmap=BitmapFactory.decodeResource(context.getResources(),id); Bitmap scaled=Bitmap.createScaledBitmap(bitmap,IMAGE_WIDTH,IMAGE_HEIGHT,true); bitmap.recycle(); return scaled; }
Example 20
From project android-wheel_1, under directory /wheel-demo/src/kankan/wheel/demo/.
Source file: SlotMachineActivity.java

/** * Loads image from resources */ private Bitmap loadImage(int id){ Bitmap bitmap=BitmapFactory.decodeResource(context.getResources(),id); Bitmap scaled=Bitmap.createScaledBitmap(bitmap,IMAGE_WIDTH,IMAGE_HEIGHT,true); bitmap.recycle(); return scaled; }
Example 21
From project android-xbmcremote, under directory /src/org/xbmc/android/remote/business/.
Source file: DiskCacheThread.java

/** * Asynchronously returns a thumb from the disk cache, or null if not available. Accessed covers get automatically added to the memory cache. * @param response Response object * @param cover Which cover to return * @param thumbSize Which size to return */ public void getCover(final DataResponse<Bitmap> response,final ICoverArt cover,final int thumbSize,final INotifiableController controller){ mHandler.post(new Runnable(){ public void run(){ if (cover != null) { final File file=ImportUtilities.getCacheFile(MediaType.getArtFolder(cover.getMediaType()),thumbSize,Crc32.formatAsHexLowerCase(cover.getCrc())); if (file.exists()) { final Bitmap bitmap=BitmapFactory.decodeFile(file.getAbsolutePath()); if (bitmap == null) { file.delete(); response.value=null; } else { MemCacheThread.addCoverToCache(cover,bitmap,thumbSize); response.value=bitmap; } } } done(controller,response); } } ); }
Example 22
From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/activity/.
Source file: AddBookActivity.java

private void setupViews(){ mSearchButton=findViewById(R.id.button_go); mSearchButton.setOnClickListener(this); mSearchButton.setEnabled(false); mSearchQuery=(EditText)findViewById(R.id.input_search_query); mSearchQuery.addTextChangedListener(new SearchFieldWatcher()); final FastBitmapDrawable cover=new FastBitmapDrawable(ImageUtilities.createShadow(BitmapFactory.decodeResource(getResources(),R.drawable.unknown_cover_no_shadow),BOOK_COVER_WIDTH,BOOK_COVER_HEIGHT)); mBooksAdapter=new SearchResultsAdapter(this,cover); final SearchResultsAdapter resultsAdapter=mBooksAdapter; final SearchResultsAdapter oldAdapter=(SearchResultsAdapter)getLastNonConfigurationInstance(); if (oldAdapter != null) { final int count=oldAdapter.getCount(); for (int i=0; i < count; i++) { resultsAdapter.add(oldAdapter.getItem(i)); } } final ListView searchResults=(ListView)findViewById(R.id.list_search_results); searchResults.setAdapter(resultsAdapter); searchResults.setOnItemClickListener(this); }
Example 23
From project AndroidExamples, under directory /DrawingExample1/src/com/robertszkutak/drawingexample1/.
Source file: DrawingExample1Activity.java

@Override public void onDraw(Canvas canvas){ Bitmap ship=BitmapFactory.decodeResource(getResources(),R.drawable.ship); int x=canvas.getWidth() / 2 - ship.getWidth() / 2; int y=canvas.getHeight() / 2 - ship.getHeight() / 2; canvas.drawColor(Color.BLACK); canvas.drawBitmap(ship,x,y,null); }
Example 24
From project androidquery, under directory /demo/src/com/androidquery/test/.
Source file: AdhocActivity.java

private Bitmap decode(File file) throws Exception { BitmapFactory.Options options=new Options(); options.inInputShareable=true; options.inPurgeable=true; FileInputStream fis=new FileInputStream(file); Bitmap result=BitmapFactory.decodeFileDescriptor(fis.getFD(),null,options); AQUtility.debug("bm",result.getWidth() + "x" + result.getHeight()); fis.close(); return result; }
Example 25
From project androidTileMapEditor_1, under directory /src/it/sineo/android/tileMapEditor/.
Source file: TiledMapView.java

public void setTile(int row,int column,String path,byte angle){ if (path != null) { try { InputStream is=null; if (path.startsWith("assets:")) { is=context.getAssets().open(path.substring(7)); } Bitmap source=BitmapFactory.decodeStream(is); Bitmap scaled=Bitmap.createScaledBitmap(source,tileSize,tileSize,true); tileMap.tileBitmaps[row][column]=scaled; tileMap.tilePaths[row][column]=path; tileMap.tileAngles[row][column]=angle; tileMap.tileMatrices[row][column]=new Matrix(); source.recycle(); } catch ( IOException ioex) { Toast.makeText(context,"Unable to load tile " + path,Toast.LENGTH_SHORT).show(); } } else { if (tileMap.tileBitmaps[row][column] != null) { tileMap.tileBitmaps[row][column].recycle(); } tileMap.tileBitmaps[row][column]=null; tileMap.tilePaths[row][column]=null; tileMap.tileAngles[row][column]=0; tileMap.tileMatrices[row][column]=null; } invalidate(); }
Example 26
From project androidtracks, under directory /src/org/sfcta/cycletracks/.
Source file: ShowMap.java

@Override public boolean draw(Canvas canvas,MapView mapView,boolean shadow,long when){ super.draw(canvas,mapView,shadow); Point screenPoint=new Point(); mapView.getProjection().toPixels(p,screenPoint); Bitmap bmp=BitmapFactory.decodeResource(getResources(),d); int height=bmp.getScaledHeight(canvas); int width=(int)(0.133333 * bmp.getScaledWidth(canvas)); canvas.drawBitmap(bmp,screenPoint.x - width,screenPoint.y - height,null); return true; }
Example 27
From project androidZenWriter, under directory /src/com/javaposse/android/zenwriter/.
Source file: AndroidZenWriterActivity.java

public static Drawable getDrawable(Context context,String filename){ BitmapFactory.Options opts=new BitmapFactory.Options(); opts.inSampleSize=2; Bitmap backgroundBitmap=BitmapFactory.decodeFile(filename,opts); if (backgroundBitmap != null) { BitmapDrawable drawable=new BitmapDrawable(context.getResources(),backgroundBitmap); return drawable; } return null; }
Example 28
From project Android_1, under directory /CarouselFragment/src/novoda/demo/.
Source file: GalleryAdapter.java

public View getView(int position,View convertView,ViewGroup parent){ View view; if (convertView == null) { final LayoutInflater inflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view=inflater.inflate(R.layout.carousel_gallery_li,null); } else { view=convertView; } final ImageView imageView=(ImageView)view.findViewById(R.id.image); Bitmap image=null; try { InputStream bitmap=mContext.getAssets().open("placeholder.png"); image=BitmapFactory.decodeStream(bitmap); } catch ( IOException e1) { e1.printStackTrace(); } imageView.setImageBitmap(image); return view; }
Example 29
From project android_packages_apps_Gallery, under directory /src/com/android/camera/.
Source file: BitmapManager.java

/** * The real place to delegate bitmap decoding to BitmapFactory. */ public Bitmap decodeFileDescriptor(FileDescriptor fd,BitmapFactory.Options options){ if (options.mCancel) { return null; } Thread thread=Thread.currentThread(); if (!canThreadDecoding(thread)) { Log.d(TAG,"Thread " + thread + " is not allowed to decode."); return null; } setDecodingOptions(thread,options); Bitmap b=BitmapFactory.decodeFileDescriptor(fd,null,options); removeDecodingOptions(thread); return b; }
Example 30
From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/app/.
Source file: CropImage.java

private void drawInTiles(Canvas canvas,BitmapRegionDecoder decoder,Rect rect,Rect dest,int sample){ int tileSize=TILE_SIZE * sample; Rect tileRect=new Rect(); BitmapFactory.Options options=new BitmapFactory.Options(); options.inPreferredConfig=Config.ARGB_8888; options.inSampleSize=sample; canvas.translate(dest.left,dest.top); canvas.scale((float)sample * dest.width() / rect.width(),(float)sample * dest.height() / rect.height()); Paint paint=new Paint(Paint.FILTER_BITMAP_FLAG); for (int tx=rect.left, x=0; tx < rect.right; tx+=tileSize, x+=TILE_SIZE) { for (int ty=rect.top, y=0; ty < rect.bottom; ty+=tileSize, y+=TILE_SIZE) { tileRect.set(tx,ty,tx + tileSize,ty + tileSize); if (tileRect.intersect(rect)) { Bitmap bitmap; synchronized (decoder) { bitmap=decoder.decodeRegion(tileRect,options); } canvas.drawBitmap(bitmap,x,y,paint); bitmap.recycle(); } } } }
Example 31
From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.
Source file: BitmapManager.java

/** * The real place to delegate bitmap decoding to BitmapFactory. */ public Bitmap decodeFileDescriptor(FileDescriptor fd,BitmapFactory.Options options){ if (options.mCancel) { return null; } Thread thread=Thread.currentThread(); if (!canThreadDecoding(thread)) { Log.d(TAG,"Thread " + thread + " is not allowed to decode."); return null; } setDecodingOptions(thread,options); Bitmap b=BitmapFactory.decodeFileDescriptor(fd,null,options); removeDecodingOptions(thread); return b; }
Example 32
From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.
Source file: FireflyRenderer.java

void loadStarTexture(){ int[] textureIds=new int[1]; mGL.glGenTextures(1,textureIds,0); mTextureId=textureIds[0]; InputStream in=null; try { in=mContext.getAssets().open("star.png"); Bitmap bitmap=BitmapFactory.decodeStream(in); mGL.glBindTexture(GL10.GL_TEXTURE_2D,mTextureId); mGL.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR); mGL.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR); GLUtils.texImage2D(GL10.GL_TEXTURE_2D,0,bitmap,0); bitmap.recycle(); } catch ( IOException e) { Log.e(LOG_TAG,"IOException opening assets."); } finally { if (in != null) { try { in.close(); } catch ( IOException e) { } } } }
Example 33
From project android_packages_apps_Tag, under directory /src/com/android/apps/tag/record/.
Source file: ImageRecord.java

public static ImageRecord parse(NdefRecord record){ MimeRecord underlyingRecord=MimeRecord.parse(record); Preconditions.checkArgument(underlyingRecord.getMimeType().startsWith("image/")); byte[] content=underlyingRecord.getContent(); Bitmap bitmap=BitmapFactory.decodeByteArray(content,0,content.length); if (bitmap == null) { throw new IllegalArgumentException("not a valid image file"); } return new ImageRecord(bitmap); }
Example 34
From project anidroid, under directory /anidroid/src/com/github/anidroid/.
Source file: FrameAnimator.java

/** * Create and return animation drawable * @param assetsFramesPath Path to folder with animation framesrelative to "assets" folder of android application * @param defaultDuration How long in milliseconds a single frameshould appear * @param oneShot Play once (true) or repeat (false) * @return AnimationDrawable instance */ public AnimationDrawable create(final String assetsFramesPath,final int defaultDuration,final boolean oneShot){ final List<String> files=assetUtil.getFileList(assetsFramesPath); final SortedMap<Integer,String> frames=frameUtil.extractFrames(files); final AnimationDrawable animationDrawable=new AnimationDrawable(); animationDrawable.setOneShot(oneShot); for ( final Integer key : frames.keySet()) { final Bitmap frame=BitmapFactory.decodeStream(assetUtil.open(frames.get(key))); animationDrawable.addFrame(new BitmapDrawable(frame),defaultDuration); } return animationDrawable; }
Example 35
From project apps-for-android, under directory /BTClickLinkCompete/src/net/clc/bt/.
Source file: AirHockey.java

/** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); self=this; mPaddleBmp=BitmapFactory.decodeResource(getResources(),R.drawable.paddlelarge); mPaddlePoints=new ArrayList<Point>(); mPaddleTimes=new ArrayList<Long>(); Intent startingIntent=getIntent(); mType=startingIntent.getIntExtra("TYPE",0); setContentView(R.layout.main); mSurface=(SurfaceView)findViewById(R.id.surface); mHolder=mSurface.getHolder(); bgPaint=new Paint(); bgPaint.setColor(Color.BLACK); goalPaint=new Paint(); goalPaint.setColor(Color.RED); ballPaint=new Paint(); ballPaint.setColor(Color.GREEN); ballPaint.setAntiAlias(true); paddlePaint=new Paint(); paddlePaint.setColor(Color.BLUE); paddlePaint.setAntiAlias(true); mPlayer=MediaPlayer.create(this,R.raw.collision); mConnection=new Connection(this,serviceReadyListener); mHolder.addCallback(self); }
Example 36
From project Backyard-Brains-Android-App, under directory /src/com/backyardbrains/view/.
Source file: UIFactory.java

public static void setupMsLineView(BackyardAndroidActivity context){ ImageView msLineView=new ImageView(context); Bitmap bmp=BitmapFactory.decodeResource(context.getResources(),R.drawable.msline); int width=context.getWindowManager().getDefaultDisplay().getWidth() / 3; int height=2; Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp,width,height,false); msLineView.setImageBitmap(resizedbitmap); msLineView.setBackgroundColor(Color.BLACK); msLineView.setScaleType(ScaleType.CENTER); LayoutParams rl=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); rl.setMargins(0,0,0,20); rl.addRule(RelativeLayout.ABOVE,R.id.millisecondsView); rl.addRule(RelativeLayout.CENTER_HORIZONTAL); RelativeLayout parentLayout=(RelativeLayout)context.findViewById(R.id.parentLayout); parentLayout.addView(msLineView,rl); }
Example 37
From project BBC-News-Reader, under directory /src/com/digitallizard/bbcnewsreader/fragments/.
Source file: FrontpageFragment.java

private void displayCategoryItems(int category){ NewsItem[] items=database.getItems(categoryNames[category],categoryRowLength); if (items != null) { for (int i=0; i < categoryRowLength; i++) { if (i < items.length) { physicalItems[category][i].setTitle(items[i].getTitle()); physicalItems[category][i].setId(items[i].getId()); byte[] thumbBytes=items[i].getThumbnailBytes(); if (Arrays.equals(thumbBytes,ReaderActivity.NO_THUMBNAIL_URL_CODE)) { physicalItems[category][i].setImage(R.drawable.no_thumb); physicalItems[category][i].setImageLoaded(false); } else if (thumbBytes != null) { Bitmap imageBitmap=BitmapFactory.decodeByteArray(thumbBytes,0,thumbBytes.length); physicalItems[category][i].setImage(imageBitmap); physicalItems[category][i].setImageLoaded(true); } else { physicalItems[category][i].setImage(R.drawable.no_thumb_grey); physicalItems[category][i].setImageLoaded(false); } } } } }
Example 38
From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/beintoosdkutility/.
Source file: ImageManager.java

private Bitmap getBitmap(String url){ try { String filename=String.valueOf(url.hashCode()); File f=new File(cacheDir,filename); try { if (f.exists()) { if (System.currentTimeMillis() > f.lastModified() + 86400000) f.delete(); } } catch ( Exception e) { if (debug) e.printStackTrace(); } Bitmap bitmap=null; if (f.exists()) bitmap=BitmapFactory.decodeFile(f.getPath()); if (bitmap != null) return bitmap; bitmap=BitmapFactory.decodeStream(new URL(url).openConnection().getInputStream()); writeFile(bitmap,f); return bitmap; } catch ( Exception ex) { if (debug) ex.printStackTrace(); return null; } }
Example 39
From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/activity/platoon/.
Source file: MenuPlatoonFragment.java

public void setupPlatoonBox(){ if (mPlatoonData != null && !mPlatoonData.isEmpty() && mTextPlatoon != null) { getPlatoonPreferences(); mTextPlatoon.setText(mPlatoonData.get(mSelectedPosition).getName() + "[" + mPlatoonData.get(mSelectedPosition).getTag()+ "]"); mImagePlatoon.setImageBitmap(BitmapFactory.decodeFile(PublicUtils.getCachePath(mContext) + mPlatoonData.get(mSelectedPosition).getImage())); } }
Example 40
From project Binaural-Beats, under directory /src/com/ihunda/android/binauralbeat/viz/.
Source file: HypnoFlash.java

public HypnoFlash(){ pFlash1=new Paint(); pFlash1.setStyle(Paint.Style.FILL); pFlash1.setColor(COLOR_FLASH1); pFlash2=new Paint(); pFlash2.setStyle(Paint.Style.FILL); pFlash2.setColor(COLOR_FLASH2); background=BitmapFactory.decodeResource(BBeat.getInstance().getResources(),R.drawable.hypnosisspiral); }
Example 41
From project Birthday-widget, under directory /Birthday/src/main/java/cz/krtinec/birthday/.
Source file: BirthdayWidget.java

protected void replaceIconWithPhoto(Context ctx,RemoteViews views,Event contact,int viewId){ InputStream is=BirthdayProvider.openPhoto(ctx,contact.getContactId()); if (is != null) { Bitmap bitmap=BitmapFactory.decodeStream(is); if (bitmap != null) { views.setImageViewBitmap(viewId,bitmap); } else { views.setImageViewResource(viewId,R.drawable.icon); } try { is.close(); } catch ( IOException e) { } } else { views.setImageViewResource(viewId,R.drawable.icon); } views.setViewVisibility(viewId,View.VISIBLE); }
Example 42
From project Birthdays, under directory /src/com/rexmenpara/birthdays/util/.
Source file: BirthdayArrayAdapter.java

/** * @return the photo URI */ private Bitmap loadContactPhoto(ContentResolver cr,long id){ Uri uri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,id); InputStream input=ContactsContract.Contacts.openContactPhotoInputStream(cr,uri); if (input == null) { return null; } return BitmapFactory.decodeStream(input); }
Example 43
protected Bitmap decodeBitmap(int maxSize,byte[] photobin){ Bitmap tmp; int h; int w; BitmapFactory.Options opts=new BitmapFactory.Options(); opts.inJustDecodeBounds=true; BitmapFactory.decodeByteArray(photobin,0,photobin.length,opts); h=opts.outHeight; w=opts.outWidth; int scaleFactor=1; while (h > maxSize && w > maxSize) { w/=2; h/=2; scaleFactor*=2; } opts=new BitmapFactory.Options(); opts.inSampleSize=scaleFactor; tmp=BitmapFactory.decodeByteArray(photobin,0,photobin.length,opts); return tmp; }
Example 44
From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.
Source file: CropBitmapManager.java

/** * The real place to delegate bitmap decoding to BitmapFactory. */ public Bitmap decodeFileDescriptor(FileDescriptor fd,BitmapFactory.Options options){ if (options.mCancel) { return null; } Thread thread=Thread.currentThread(); if (!canThreadDecoding(thread)) { return null; } setDecodingOptions(thread,options); Bitmap b=BitmapFactory.decodeFileDescriptor(fd,null,options); removeDecodingOptions(thread); return b; }
Example 45
From project BookingRoom, under directory /src/org/androidaalto/bookingroom/view/.
Source file: WeekView.java

private void copyWartermarkToCanvas(Canvas canvas){ Bitmap watermark=BitmapFactory.decodeResource(mResources,R.drawable.background_vg_android); Rect src=mSrcRect; src.top=0; src.left=0; src.bottom=watermark.getHeight(); src.right=watermark.getWidth(); Rect dst=mDestRect; dst.top=mBitmapHeight / 2 - watermark.getHeight() / 2; dst.bottom=mBitmapHeight / 2 + watermark.getHeight() / 2; dst.left=mNavigationWidth; dst.right=mViewWidth - 2 * mNavigationWidth; canvas.drawBitmap(watermark,src,dst,null); }
Example 46
From project BreizhCamp-android, under directory /src/org/breizhjug/breizhcamp/util/.
Source file: ImageLoader.java

private Bitmap decodeFile(File f){ try { return BitmapFactory.decodeStream(new FileInputStream(f)); } catch ( FileNotFoundException e) { } return null; }
Example 47
From project Catroid-maven-playground, under directory /src/main/java/at/tugraz/ist/catroid/common/.
Source file: CostumeData.java

public int[] getResolution(){ if (width != null && height != null) { return new int[]{width,height}; } BitmapFactory.Options options=new BitmapFactory.Options(); options.inJustDecodeBounds=true; BitmapFactory.decodeFile(getAbsolutePath(),options); width=options.outWidth; height=options.outHeight; return new int[]{width,height}; }
Example 48
From project CHMI, under directory /src/org/kaldax/app/chmi/.
Source file: CHMIWidgetProvider.java

public static void updateWidgetBitmap(Context context,RemoteViews remoteViews,byte[] image_buffer){ Bitmap bmp; if (image_buffer != null) { bmp=BitmapFactory.decodeStream(new ByteArrayInputStream(image_buffer)); } else { bmp=BitmapFactory.decodeResource(context.getResources(),R.drawable.r_30min_empty); } remoteViews.setImageViewBitmap(R.id.ImageViewWidget,bmp); }
Example 49
From project cicada, under directory /samples/hellocicada/src/org/cicadasong/samples/hellocicada/.
Source file: HelloCicada.java

@Override public void onReceive(Context context,Intent intent){ ButtonPress event=ButtonPress.parseIntent(intent); if ((event == null) || !event.hasButtonsPressed(Button.BOTTOM_RIGHT)) { return; } Bitmap bitmap=BitmapFactory.decodeStream(context.getResources().openRawResource(R.drawable.cicada)); ApolloIntents.pushBitmap(context,bitmap); ApolloIntents.vibrate(context,500,200,3); }
Example 50
From project CineShowTime-Android, under directory /Libraries/CineShowTime/src/com/binomed/showtime/android/layout/view/.
Source file: PageInfoView.java

private void init(){ LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.tab_movie_info,this); bitmapRateOff=BitmapFactory.decodeResource(getResources(),R.drawable.rate_star_small_off); bitmapRateHalf=BitmapFactory.decodeResource(getResources(),R.drawable.rate_star_small_half); bitmapRateOn=BitmapFactory.decodeResource(getResources(),R.drawable.rate_star_small_on); imageDownloader=new ImageDownloader(); initView(); initListeners(); }