裁剪图片

裁剪图片

/**
      * 截图后另存为
      *
      * @param rect
      * @param path
      * @throws IOException
      * @throws InterruptedException
      */
      @SuppressWarnings ( "static-access" )
      public void cutBitmp() throws IOException, InterruptedException {

           int imgWidth , imgHeigth , cc = 0;
          Bitmap m = null ;
                   
               m = BitmapFactory.decodeFile( "/sdcard/wlk/image/12.jpg" );
              

               imgWidth = m .getWidth();
               imgHeigth = m .getHeight();
              
              System. out .println( "jieguo" + imgWidth );
              System. out .println( "jieguo" + imgHeigth );
              
               imgWidth = imgWidth - randomN(40);
               imgHeigth = imgHeigth - randomN(20);

               m = m .createBitmap( m , 0, 0, imgWidth , imgHeigth );
              System. out .println( m + "jieguo" );
              saveBitMapToSdcard( m , 12);
          
     }

      /**
      * 获得全图并从全图中截图
      *
      * @param m
      * @param newName
      * @throws IOException
      * @throws InterruptedException
      */
      public void saveBitMapToSdcard(Bitmap m , int newName ) throws IOException, InterruptedException {
          FileOutputStream out = null ;
          String path = "/sdcard/wxpyq/12.jpg" ;
          System. out .println( "jieguo" + path );
          
           out = new FileOutputStream( path );
          System. out .println( out + "jieguo" );
           if ( out != null ) {
              System. out .println( "buchunzaijieguo" );
               m .compress(Bitmap.CompressFormat. JPEG , 90, out );
               out .close();
          }
     }

在AndroidManifest.xml中添加权限
< uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" />

    我是一条你看不见的分割线

图片转色
m = BitmapFactory.decodeFile(imgPath + j + ".jpg");
imgWidth = m.getWidth();
imgHeigth = m.getHeight();
// imgPixel = new int[imgWidth * imgHeigth];
//
// /**
// * pixels       接收位图颜色值的数组 
// offset      写入到pixels[]中的第一个像素索引值 
// stride      pixels[]中的行间距个数值(必须大于等于位图宽度)。可以为负数 
// x            从位图中读取的第一个像素的x坐标值。 
// y           从位图中读取的第一个像素的y坐标值 
// width      从每一行中读取的像素宽度 
// height    读取的行数
// */
// m.getPixels(imgPixel, 0, imgWidth, 0, 0, imgWidth, imgHeigth);
//
// for (int n = 0; n < imgWidth * imgHeigth; n++) {
// if((imgPixel[n] & 0x00ffffff) == 0x00ffffff){
// imgPixel[n] = 0x7f0000ff;  
// }
// }
//
// String cmd = "cp /sdcard/wlk/image/" + j + ".jpg /sdcard/wxpyq/" + j + ".jpg";
// Runtime.getRuntime().exec(cmd);
// Thread.sleep(1000);
//
// m2 = BitmapFactory.decodeFile(img2Path + j + ".jpg");
//
// m.setPixels(imgPixel, 0, imgWidth, 0, 0, imgWidth, imgHeigth);
//
// Runtime.getRuntime().exec(curlImgCmd + "wxpyq/" + j + ".jpg");

  我是一条你看不见的分割线

刷新媒体库
private void updateGallery(String filename)//filename是我们的文件全名,包括后缀哦
{
MediaScannerConnection.scanFile(this,
 new String[] { filename }, null,
 new MediaScannerConnection.OnScanCompletedListener() {
 public void onScanCompleted(String path, Uri uri) {
 Log.i("ExternalStorage", "Scanned " + path + ":");
 Log.i("ExternalStorage", "-> uri=" + uri);
 }
 });
}

     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值