public static void  draw_the_grid(Canvas this_g,  Vector these_labels)
     {         
        double rounded_max = 0.0;
        double rounded_min = 0.0;
        double rounded_max_temp;
        Object curElt;  
        String[] cur_elt_array;
        int left_margin_d, right_margin_d;      

        if( draw_only_this_idx == -1)      
           curElt = these_labels.elementAt(0);  // default  it to 1st one if non set 
        else
           curElt = these_labels.elementAt(draw_only_this_idx);  // now just the 1st elt

        cur_elt_array = (String[])curElt;

        rounded_max = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[2]) , true);
        rounded_min = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[3]) , false);

       // ok so now we have the max value of the set just get a cool ceiling and we go on
        final Paint paint = new Paint();  
        paint.setTextSize(15);

       left_margin_d =  getCurTextLengthInPixels(paint, Double.toString(rounded_max));
       //keep the position for later drawing -- leave space for the legend
       int p_height = 170;
       int p_width = 220;
       int[] tmp_draw_sizes = {2 + left_margin_d, 25,p_width - 2 - 
        left_margin_d ,p_height - 25 -5};
       drawSizes = tmp_draw_sizes; //keep it for later processing

        //with the mzrgins worked out draw the plotting grid
       paint.setStyle(Paint.Style.FILL); 
       paint.setColor(Color.WHITE );  

       // Android does by coords
       this_g.drawRect(drawSizes[0], drawSizes[1],drawSizes[0]+ 
        drawSizes[2], drawSizes[1]+ drawSizes[3] , paint);

       paint.setColor(Color.GRAY );       

        // finally draw the grid      

       paint.setStyle(Paint.Style.STROKE); 
       this_g.drawRect(drawSizes[0], drawSizes[1],drawSizes[0]+ 
        drawSizes[2], drawSizes[1]+ drawSizes[3] , paint);

           for(int i=1; i < 5 ; i++)
           {
               this_g.drawLine(drawSizes[0], drawSizes[1] + 
        (i * drawSizes[3] / 5), drawSizes[0] + drawSizes[2], 
        drawSizes[1] + (i * drawSizes[3] / 5), paint);
               this_g.drawLine(drawSizes[0]+ (i * drawSizes[2] / 5), 
        drawSizes[1], drawSizes[0] + (i * drawSizes[2] / 5), 
        drawSizes[1] + drawSizes[3], paint);
           }

          // good for one value
           print_axis_values_4_grid(this_g, cur_elt_array[1] , 
        Double.toString(rounded_max) , Double.toString(rounded_min), 
        cur_elt_array[0] , 2 ,0 );

     } 

参考《android开发艺术探索》

1.图片压缩功能类ImageResizer

<pre>
public class ImageResizer{
private static final String TAG = “ImageResizer”;

public ImageResizer(){
}

美高梅电子游戏 ,public Bitmap decodeSampledBitmapFromResource(Resource res,int resId,int
reqWidth,int reqHeight){
//First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res,resId,options);
//calculate inSampleSize
options.inSampleSize =
calculateInSampleSize(options,reqWidth,reqHeight);
//decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res,resId,options);
}

public Bitmap decodeSampledBitmapFromFileDescriptor(FileDescriptor
fd,int reqWidth, int reqHeight){
//First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fd,null,options);
//calculate inSampleSize
options.inSampleSize =
calculateInSampleSize(options,reqWidth,reqHeight);
//decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFileDescriptor(fd,null,options);
}

public int calculateInSampleSize(BitmapFactory.Options options, int
reqWidth, int reqHeight){
if(reqWidth == 0 || reqHeight == 0){
return 1;
}
//Raw height and width of image
final int width = options.outWidth;
final int height = options.outHeight;
Log.d(TAG,”origin,w=”+width+”h=”+height);
int inSampleSize = 1;

  if(height > reqHeight || width > reqWidth){
     final int halfHeight = height / 2;
     final int halfWidth = width / 2;
     while((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth){
        inSampleSize *= 2;
     }
  }
  Log.d(TAG,"sampleSize:"+inSampleSize);
  return inSampleSize;

}
}
</pre>

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注