Java Code Examples for android.graphics.Bitmap

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: BitmapHolder.java

  32 
vote

public Bitmap getBitmap(int width,int height,int index){
  if (width == 0 || height == 0)   return null;
  BitmapKey key=new BitmapKey(width,height,index);
  if (!cache.containsKey(key)) {
    Bitmap bitmap=Bitmap.createBitmap(key.getWidth(),key.getHeight(),Bitmap.Config.ARGB_8888);
    new PhantomReference<Bitmap>(bitmap,bitmapReferenceQueue);
    cache.put(key,bitmap);
  }
  return cache.get(key);
}
 

Example 2

From project Airports, under directory /src/com/nadmm/airports/utils/.

Source file: UiUtils.java

  32 
vote

public static Drawable getRotatedDrawable(Context context,int resid,float rotation){
  Resources res=context.getResources();
  Bitmap bmp=BitmapFactory.decodeResource(res,resid);
  Bitmap rotated=Bitmap.createBitmap(bmp.getWidth(),bmp.getHeight(),Bitmap.Config.ARGB_8888);
  Canvas canvas=new Canvas(rotated);
  canvas.setDensity(Bitmap.DENSITY_NONE);
  canvas.rotate(rotation,bmp.getWidth() / 2,bmp.getHeight() / 2);
  canvas.drawBitmap(bmp,0,0,sPaint);
  return new BitmapDrawable(res,rotated);
}
 

Example 3

From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/.

Source file: ReportDetailsActivity.java

  32 
vote

private void RotatePicture(ImageView imageView){
  Bitmap picture=null;
  picture=((BitmapDrawable)(imageView.getDrawable())).getBitmap();
  Matrix m=new Matrix();
  m.postRotate(90);
  picture=Bitmap.createBitmap(picture,0,0,picture.getWidth(),picture.getHeight(),m,true);
  imageView.setImageBitmap(picture);
}
 

Example 4

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/.

Source file: DisputeActivity.java

  32 
vote

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 5

From project andlytics, under directory /src/com/github/andlyticsproject/.

Source file: BaseDetailsActivity.java

  32 
vote

@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 6

From project Android, under directory /app/src/main/java/com/github/mobile/util/.

Source file: AvatarLoader.java

  32 
vote

/** 
 * Get image for user
 * @param userId
 * @return image
 */
protected BitmapDrawable getImage(final String userId){
  File avatarFile=new File(avatarDir,userId);
  if (!avatarFile.exists() || avatarFile.length() == 0)   return null;
  Bitmap bitmap=decode(avatarFile);
  if (bitmap != null)   return new BitmapDrawable(context.getResources(),bitmap);
 else {
    avatarFile.delete();
    return null;
  }
}
 

Example 7

From project android-api-demos, under directory /src/com/mobeelizer/demos/activities/.

Source file: ConflictsActivity.java

  32 
vote

/** 
 * 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 8

From project android-cropimage, under directory /src/com/android/camera/.

Source file: BitmapManager.java

  32 
vote

/** 
 * 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 9

From project android-joedayz, under directory /Proyectos/androidMDWCompleto/src/com/android/mdw/demo/.

Source file: Main.java

  32 
vote

@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 10

From project android-mapviewballoons, under directory /android-mapviewballoons-example/src/mapviewballoons/example/custom/.

Source file: CustomBalloonOverlayView.java

  32 
vote

@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 11

From project Android-Simple-Social-Sharing, under directory /SimpleSocialSharingExample/src/com/nostra13/example/socialsharing/.

Source file: FacebookActivity.java

  32 
vote

private void publishImage(){
  Bitmap bmp=((BitmapDrawable)getResources().getDrawable(R.drawable.ic_app)).getBitmap();
  ByteArrayOutputStream stream=new ByteArrayOutputStream();
  bmp.compress(Bitmap.CompressFormat.JPEG,100,stream);
  byte[] bitmapdata=stream.toByteArray();
  facebook.publishImage(bitmapdata,Constants.FACEBOOK_SHARE_IMAGE_CAPTION);
}
 

Example 12

From project android-wheel, under directory /wheel-demo/src/kankan/wheel/demo/.

Source file: SlotMachineActivity.java

  32 
vote

/** 
 * 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 13

From project android-wheel_1, under directory /wheel-demo/src/kankan/wheel/demo/.

Source file: SlotMachineActivity.java

  32 
vote

/** 
 * 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 14

From project android-xbmcremote, under directory /src/org/xbmc/android/remote/business/.

Source file: DiskCacheThread.java

  32 
vote

/** 
 * Synchronously returns a thumb from the disk cache, or null if not  available.
 * @param cover Which cover to return
 * @return Bitmap or null if not available.
 */
public static Bitmap getCover(ICoverArt cover,int thumbSize){
  final File file=ImportUtilities.getCacheFile(MediaType.getArtFolder(cover.getMediaType()),thumbSize,Crc32.formatAsHexLowerCase(cover.getCrc()));
  if (file.exists()) {
    final Bitmap bitmap=BitmapFactory.decodeFile(file.getAbsolutePath());
    MemCacheThread.addCoverToCache(cover,bitmap,thumbSize);
    return bitmap;
  }
 else   return null;
}
 

Example 15

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/activity/.

Source file: AddBookActivity.java

  32 
vote

ResultBook(BooksStore.Book book){
  this.book=book;
  Bitmap bitmap=ImageUtilities.createShadow(book.loadCover(BooksStore.ImageSize.THUMBNAIL),BOOK_COVER_WIDTH,BOOK_COVER_HEIGHT);
  if (bitmap != null) {
    cover=new FastBitmapDrawable(bitmap);
  }
 else {
    cover=null;
  }
  title=book.getTitle();
  authors=TextUtilities.join(book.getAuthors(),", ");
  text=title + ' ' + authors;
}
 

Example 16

From project AndroidExamples, under directory /DrawingExample1/src/com/robertszkutak/drawingexample1/.

Source file: DrawingExample1Activity.java

  32 
vote

@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 17

From project androidquery, under directory /demo/src/com/androidquery/test/.

Source file: AdhocActivity.java

  32 
vote

public void photoCb(String url,File file,AjaxStatus status) throws Exception {
  if (file == null)   return;
  AQUtility.debug("file cb",file.length());
  AQUtility.debug("ui",AQUtility.isUIThread());
  for (int i=0; i < 50; i++) {
    String tag="image#" + (i + 1);
    AQUtility.time(tag);
    Bitmap bm=decode(file);
    cache.put(i + "",bm);
    AQUtility.timeEnd(tag,0);
  }
}
 

Example 18

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/widget/.

Source file: IcsProgressBar.java

  31 
vote

/** 
 * Converts a drawable to a tiled version of itself. It will recursively traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable,boolean clip){
  if (drawable instanceof LayerDrawable) {
    LayerDrawable background=(LayerDrawable)drawable;
    final int N=background.getNumberOfLayers();
    Drawable[] outDrawables=new Drawable[N];
    for (int i=0; i < N; i++) {
      int id=background.getId(i);
      outDrawables[i]=tileify(background.getDrawable(i),(id == android.R.id.progress || id == android.R.id.secondaryProgress));
    }
    LayerDrawable newBg=new LayerDrawable(outDrawables);
    for (int i=0; i < N; i++) {
      newBg.setId(i,background.getId(i));
    }
    return newBg;
  }
 else   if (drawable instanceof BitmapDrawable) {
    final Bitmap tileBitmap=((BitmapDrawable)drawable).getBitmap();
    if (mSampleTile == null) {
      mSampleTile=tileBitmap;
    }
    final ShapeDrawable shapeDrawable=new ShapeDrawable(getDrawableShape());
    final BitmapShader bitmapShader=new BitmapShader(tileBitmap,Shader.TileMode.REPEAT,Shader.TileMode.CLAMP);
    shapeDrawable.getPaint().setShader(bitmapShader);
    return (clip) ? new ClipDrawable(shapeDrawable,Gravity.LEFT,ClipDrawable.HORIZONTAL) : shapeDrawable;
  }
  return drawable;
}
 

Example 19

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/widget/.

Source file: IcsProgressBar.java

  31 
vote

/** 
 * Converts a drawable to a tiled version of itself. It will recursively traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable,boolean clip){
  if (drawable instanceof LayerDrawable) {
    LayerDrawable background=(LayerDrawable)drawable;
    final int N=background.getNumberOfLayers();
    Drawable[] outDrawables=new Drawable[N];
    for (int i=0; i < N; i++) {
      int id=background.getId(i);
      outDrawables[i]=tileify(background.getDrawable(i),(id == android.R.id.progress || id == android.R.id.secondaryProgress));
    }
    LayerDrawable newBg=new LayerDrawable(outDrawables);
    for (int i=0; i < N; i++) {
      newBg.setId(i,background.getId(i));
    }
    return newBg;
  }
 else   if (drawable instanceof BitmapDrawable) {
    final Bitmap tileBitmap=((BitmapDrawable)drawable).getBitmap();
    if (mSampleTile == null) {
      mSampleTile=tileBitmap;
    }
    final ShapeDrawable shapeDrawable=new ShapeDrawable(getDrawableShape());
    final BitmapShader bitmapShader=new BitmapShader(tileBitmap,Shader.TileMode.REPEAT,Shader.TileMode.CLAMP);
    shapeDrawable.getPaint().setShader(bitmapShader);
    return (clip) ? new ClipDrawable(shapeDrawable,Gravity.LEFT,ClipDrawable.HORIZONTAL) : shapeDrawable;
  }
  return drawable;
}
 

Example 20

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/widget/.

Source file: ActionBarContainer.java

  31 
vote

public ActionBarContainer(Context context,AttributeSet attrs){
  super(context,attrs);
  setBackgroundDrawable(null);
  TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.SherlockActionBar);
  mBackground=a.getDrawable(R.styleable.SherlockActionBar_background);
  mStackedBackground=a.getDrawable(R.styleable.SherlockActionBar_backgroundStacked);
  if (mStackedBackground instanceof ColorDrawable && Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    Bitmap bitmap=Bitmap.createBitmap(1,1,Bitmap.Config.ARGB_8888);
    Canvas c=new Canvas(bitmap);
    mStackedBackground.draw(c);
    int color=bitmap.getPixel(0,0);
    bitmap.recycle();
    mStackedBackground=new IcsColorDrawable(color);
  }
  if (getId() == R.id.abs__split_action_bar) {
    mIsSplit=true;
    mSplitBackground=a.getDrawable(R.styleable.SherlockActionBar_backgroundSplit);
  }
  a.recycle();
  setWillNotDraw(mIsSplit ? mSplitBackground == null : mBackground == null && mStackedBackground == null);
}
 

Example 21

From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/internal/widget/.

Source file: IcsProgressBar.java

  31 
vote

/** 
 * Converts a drawable to a tiled version of itself. It will recursively traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable,boolean clip){
  if (drawable instanceof LayerDrawable) {
    LayerDrawable background=(LayerDrawable)drawable;
    final int N=background.getNumberOfLayers();
    Drawable[] outDrawables=new Drawable[N];
    for (int i=0; i < N; i++) {
      int id=background.getId(i);
      outDrawables[i]=tileify(background.getDrawable(i),(id == android.R.id.progress || id == android.R.id.secondaryProgress));
    }
    LayerDrawable newBg=new LayerDrawable(outDrawables);
    for (int i=0; i < N; i++) {
      newBg.setId(i,background.getId(i));
    }
    return newBg;
  }
 else   if (drawable instanceof BitmapDrawable) {
    final Bitmap tileBitmap=((BitmapDrawable)drawable).getBitmap();
    if (mSampleTile == null) {
      mSampleTile=tileBitmap;
    }
    final ShapeDrawable shapeDrawable=new ShapeDrawable(getDrawableShape());
    final BitmapShader bitmapShader=new BitmapShader(tileBitmap,Shader.TileMode.REPEAT,Shader.TileMode.CLAMP);
    shapeDrawable.getPaint().setShader(bitmapShader);
    return (clip) ? new ClipDrawable(shapeDrawable,Gravity.LEFT,ClipDrawable.HORIZONTAL) : shapeDrawable;
  }
  return drawable;
}
 

Example 22

From project android-bankdroid, under directory /src/com/liato/bankdroid/banking/banks/Nordea/.

Source file: CaptchaBreaker.java

  31 
vote

public static String iMustBreakYou(Bitmap bitmap){
  int width=bitmap.getWidth();
  int height=bitmap.getHeight();
  ArrayList<Segment> segments=new ArrayList<Segment>();
  boolean numberpart=false;
  Segment segment=new Segment();
  for (int x=0; x < width; x++) {
    boolean numberpartcol=false;
    for (int y=0; y < height; y++) {
      int color=bitmap.getPixel(x,y);
      if (color != 0xffffffff) {
        if (!numberpart) {
          segment.start=x;
        }
        numberpart=numberpartcol=true;
        break;
      }
    }
    if (numberpart && !numberpartcol) {
      numberpart=false;
      segment.end=x - 1;
      segments.add(segment);
      segment=new Segment();
    }
  }
  if (segment.end == -1 && segment.start >= 0) {
    segment.end=width - 1;
    segments.add(segment);
  }
  StringBuilder sb=new StringBuilder(segments.size());
  for (  Segment s : segments) {
    Bitmap numberSegment=Bitmap.createBitmap(bitmap,s.start,0,s.end - s.start,height);
    sb.append(extractNumber(numberSegment));
    numberSegment.recycle();
    numberSegment=null;
  }
  return sb.toString();
}
 

Example 23

From project Android-File-Manager-Tablet, under directory /src/com/nexes/manager/tablet/.

Source file: MultiSelectHandler.java

  31 
vote

public View addFile(String file){
  if (mFileList.contains(file))   return null;
  view=mInflater.inflate(R.layout.multiselect_layout,null);
  ImageView image=(ImageView)view.findViewById(R.id.multi_icon);
  TextView text=(TextView)view.findViewById(R.id.multi_text);
  String ext="";
  if (new File(file).isDirectory()) {
    text.setText(file.substring(file.lastIndexOf("/") + 1,file.length()));
    ext="dir";
  }
 else {
    text.setText(file.substring(file.lastIndexOf("/") + 1,file.lastIndexOf(".")));
    ext=file.substring(file.lastIndexOf(".") + 1,file.length());
  }
  if (mThumbnail == null) {
    setImage(ext,image);
  }
 else {
    if (ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg")|| ext.equalsIgnoreCase("gif")) {
      Bitmap b=Bitmap.createScaledBitmap(mThumbnail.isBitmapCached(file).getBitmap(),58,58,false);
      image.setImageBitmap(b);
    }
 else {
      setImage(ext,image);
    }
  }
  mFileList.add(file);
  return view;
}
 

Example 24

From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/adapters/.

Source file: GifFramesAdapter.java

  31 
vote

@Override public View getView(int position,View convertView,ViewGroup parent){
  if (convertView == null)   convertView=this.mInflater.inflate(R.layout.view_frame_thumb,null);
  int desiredSize=convertView.getResources().getDimensionPixelSize(R.dimen.create_list_thumb_size);
  String imagePath=this.mImageIds.get(position);
  ImageView thumbImage=(ImageView)convertView.findViewById(R.id.img_item_icon);
  TextView itemTitle=(TextView)convertView.findViewById(R.id.tv_item_title);
  itemTitle.setText("" + (position + 1));
  int outWidth=desiredSize;
  int outHeight=desiredSize;
  thumbImage.setLayoutParams(new RelativeLayout.LayoutParams(outWidth,outHeight));
  convertView.setLayoutParams(new Gallery.LayoutParams(outWidth,outHeight));
  Bitmap bitmap=ImageHelper.getDesirableBitmap(imagePath,desiredSize);
  if (bitmap != null) {
    thumbImage.setImageBitmap(bitmap);
    if (bitmap.getHeight() > bitmap.getWidth()) {
      outWidth=(int)(desiredSize * ((float)bitmap.getWidth() / bitmap.getHeight()));
    }
 else {
      outHeight=(int)(desiredSize * ((float)bitmap.getHeight() / bitmap.getWidth()));
    }
    thumbImage.setLayoutParams(new RelativeLayout.LayoutParams(outWidth,outHeight));
    convertView.setLayoutParams(new Gallery.LayoutParams(outWidth,outHeight));
  }
  return convertView;
}
 

Example 25

From project android-gltron, under directory /GlTron/src/com/glTron/Video/.

Source file: GLTexture.java

  31 
vote

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 26

From project Android-MapForgeFragment, under directory /library-common/src/com/jakewharton/android/mapsforge_fragment/.

Source file: MapView.java

  31 
vote

/** 
 * Draws a tile bitmap at the right position on the MapView bitmap.
 * @param mapGeneratorJob the job with the tile.
 * @param bitmap the bitmap to be drawn.
 */
synchronized void putTileOnBitmap(MapGeneratorJob mapGeneratorJob,Bitmap bitmap){
  if (this.mapViewPixelX - mapGeneratorJob.tile.pixelX > Tile.TILE_SIZE || this.mapViewPixelX + getWidth() < mapGeneratorJob.tile.pixelX) {
    return;
  }
 else   if (this.mapViewPixelY - mapGeneratorJob.tile.pixelY > Tile.TILE_SIZE || this.mapViewPixelY + getHeight() < mapGeneratorJob.tile.pixelY) {
    return;
  }
 else   if (mapGeneratorJob.tile.zoomLevel != this.zoomLevel) {
    return;
  }
  if (this.zoomAnimator.isExecuting()) {
    return;
  }
  if (!matrixIsIdentity()) {
    this.mapViewBitmap2.eraseColor(MAP_VIEW_BACKGROUND);
    this.mapViewCanvas.setBitmap(this.mapViewBitmap2);
synchronized (this.matrix) {
      this.mapViewCanvas.drawBitmap(this.mapViewBitmap1,this.matrix,null);
      this.matrix.reset();
    }
    Bitmap mapViewBitmapSwap=this.mapViewBitmap1;
    this.mapViewBitmap1=this.mapViewBitmap2;
    this.mapViewBitmap2=mapViewBitmapSwap;
  }
  this.mapViewCanvas.drawBitmap(bitmap,(float)(mapGeneratorJob.tile.pixelX - this.mapViewPixelX),(float)(mapGeneratorJob.tile.pixelY - this.mapViewPixelY),null);
}
 

Example 27

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: OcrRecognizeAsyncTask.java

  31 
vote

@Override protected Boolean doInBackground(Void... arg0){
  long start=System.currentTimeMillis();
  Bitmap bitmap=activity.getCameraManager().buildLuminanceSource(data,width,height).renderCroppedGreyscaleBitmap();
  String textResult;
  try {
    baseApi.setImage(ReadFile.readBitmap(bitmap));
    textResult=baseApi.getUTF8Text();
    timeRequired=System.currentTimeMillis() - start;
    if (textResult == null || textResult.equals("")) {
      return false;
    }
    ocrResult=new OcrResult();
    ocrResult.setWordConfidences(baseApi.wordConfidences());
    ocrResult.setMeanConfidence(baseApi.meanConfidence());
    ocrResult.setRegionBoundingBoxes(baseApi.getRegions().getBoxRects());
    ocrResult.setTextlineBoundingBoxes(baseApi.getTextlines().getBoxRects());
    ocrResult.setWordBoundingBoxes(baseApi.getWords().getBoxRects());
    ocrResult.setStripBoundingBoxes(baseApi.getStrips().getBoxRects());
    ocrResult.setCharacterBoundingBoxes(baseApi.getCharacters().getBoxRects());
  }
 catch (  RuntimeException e) {
    Log.e("OcrRecognizeAsyncTask","Caught RuntimeException in request to Tesseract. Setting state to CONTINUOUS_STOPPED.");
    e.printStackTrace();
    try {
      baseApi.clear();
      activity.stopHandler();
    }
 catch (    NullPointerException e1) {
    }
    return false;
  }
  timeRequired=System.currentTimeMillis() - start;
  ocrResult.setBitmap(bitmap);
  ocrResult.setText(textResult);
  ocrResult.setRecognitionTimeRequired(timeRequired);
  return true;
}
 

Example 28

From project android-thaiime, under directory /latinime/src/com/sugree/inputmethod/latin/.

Source file: SuggestionsView.java

  31 
vote

private static Drawable getMoreSuggestionsHint(Resources res,float textSize,int color){
  final Paint paint=new Paint();
  paint.setAntiAlias(true);
  paint.setTextAlign(Align.CENTER);
  paint.setTextSize(textSize);
  paint.setColor(color);
  final Rect bounds=new Rect();
  paint.getTextBounds(MORE_SUGGESTIONS_HINT,0,MORE_SUGGESTIONS_HINT.length(),bounds);
  final int width=Math.round(bounds.width() + 0.5f);
  final int height=Math.round(bounds.height() + 0.5f);
  final Bitmap buffer=Bitmap.createBitmap(width,(height * 3 / 2),Bitmap.Config.ARGB_8888);
  final Canvas canvas=new Canvas(buffer);
  canvas.drawText(MORE_SUGGESTIONS_HINT,width / 2,height,paint);
  return new BitmapDrawable(res,buffer);
}
 

Example 29

From project AChartEngine, under directory /achartengine/src/org/achartengine/.

Source file: GraphicalView.java

  29 
vote

/** 
 * Saves the content of the graphical view to a bitmap.
 * @return the bitmap
 */
public Bitmap toBitmap(){
  setDrawingCacheEnabled(false);
  if (!isDrawingCacheEnabled()) {
    setDrawingCacheEnabled(true);
  }
  if (mRenderer.isApplyBackgroundColor()) {
    setDrawingCacheBackgroundColor(mRenderer.getBackgroundColor());
  }
  setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
  return getDrawingCache(true);
}
 

Example 30

From project agit, under directory /agit/src/main/java/com/madgag/agit/.

Source file: AgitModule.java

  29 
vote

public ImageSession<String,Bitmap> get(){
  Log.i("BRP","ImageSessionProvider INVOKED");
  ImageProcessor<Bitmap> imageProcessor=new ScaledBitmapDrawableGenerator(34,resources);
  ImageResourceDownloader<String,Bitmap> downloader=new GravatarBitmapDownloader();
  File file=new File(Environment.getExternalStorageDirectory(),"gravatars");
  ImageResourceStore<String,Bitmap> imageResourceStore=new BitmapFileStore<String>(file);
  return new ImageSession<String,Bitmap>(imageProcessor,downloader,imageResourceStore,resources.getDrawable(R.drawable.loading_34_centred));
}
 

Example 31

From project Android-File-Manager, under directory /src/com/nexes/manager/.

Source file: ThumbnailCreator.java

  29 
vote

@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 32

From project android-flip, under directory /FlipView/FlipLibrary/src/com/aphidmobile/flip/.

Source file: Texture.java

  29 
vote

public static Texture createTexture(Bitmap bitmap,FlipRenderer renderer,GL10 gl){
  Texture t=new Texture();
  t.renderer=renderer;
  Assert.assertTrue("bitmap should not be null or recycled",bitmap != null && !bitmap.isRecycled());
  int w=Integer.highestOneBit(bitmap.getWidth() - 1) << 1;
  int h=Integer.highestOneBit(bitmap.getHeight() - 1) << 1;
  t.contentWidth=bitmap.getWidth();
  t.contentHeight=bitmap.getHeight();
  t.width=w;
  t.height=h;
  if (AphidLog.ENABLE_DEBUG)   AphidLog.d("createTexture: %d, %d; POT: %d, %d",bitmap.getWidth(),bitmap.getHeight(),w,h);
  gl.glGenTextures(1,t.id,0);
  gl.glBindTexture(GL_TEXTURE_2D,t.id[0]);
  gl.glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  gl.glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,null);
  GLUtils.texSubImage2D(GL_TEXTURE_2D,0,0,0,bitmap);
  return t;
}
 

Example 33

From project android-voip-service, under directory /src/main/java/org/linphone/core/.

Source file: AndroidVideoWindowImpl.java

  29 
vote

public AndroidVideoWindowImpl(SurfaceView view){
  useGLrendering=(view instanceof GLSurfaceView);
  mView=view;
  mBitmap=null;
  mSurface=null;
  mListener=null;
  view.getHolder().addCallback(new Callback(){
    public void surfaceChanged(    SurfaceHolder holder,    int format,    int width,    int height){
      Log.i("Surface is being changed.");
      if (!useGLrendering) {
synchronized (AndroidVideoWindowImpl.this) {
          mBitmap=Bitmap.createBitmap(width,height,Config.RGB_565);
          mSurface=holder.getSurface();
        }
      }
      if (mListener != null)       mListener.onSurfaceReady(AndroidVideoWindowImpl.this);
      Log.w("Video display surface changed");
    }
    public void surfaceCreated(    SurfaceHolder holder){
      Log.w("Video display surface created");
    }
    public void surfaceDestroyed(    SurfaceHolder holder){
      if (!useGLrendering) {
synchronized (AndroidVideoWindowImpl.this) {
          mSurface=null;
          mBitmap=null;
        }
      }
      if (mListener != null)       mListener.onSurfaceDestroyed(AndroidVideoWindowImpl.this);
      Log.d("Video display surface destroyed");
    }
  }
);
  if (useGLrendering) {
    renderer=new Renderer();
    ((GLSurfaceView)mView).setRenderer(renderer);
    ((GLSurfaceView)mView).setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
  }
}