精华内容
下载资源
问答
  • /*Java代码 将Drawable转化Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawa...
    /*Java代码  将Drawable转化为Bitmap */
      Bitmap drawableToBitmap(Drawable drawable)
      {
       int width = drawable.getIntrinsicWidth();
       int height = drawable.getIntrinsicHeight();
              
       Bitmap bitmap = Bitmap.createBitmap(width, height,drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888: Bitmap.Config.RGB_565);
       Canvas canvas = new Canvas(bitmap);
       //canvas.drawColor(0xff33B5E5);       
       drawable.setBounds(0,0,width,height);
       drawable.draw(canvas);
               
       return bitmap;      
      }

    转载于:https://my.oschina.net/zhangphil/blog/1601877

    展开全文
  • Android把drawable转化bitmap

    千次阅读 2016-07-01 17:06:28
    在util下写一方法把drawable转化bitmappublic class ImageUtil { //返回一个宽度和高度都为100个像素的bitmap public static Bitmap getResizeBitmap(BitmapDrawable drawable){ // 把drawable转化bitmap ...

    在util下写一方法把drawable转化为bitmap

    public class ImageUtil {
    //返回一个宽度和高度都为100个像素的bitmap
        public static Bitmap getResizeBitmap(BitmapDrawable drawable, Context context){
    //      把drawable转化为bitmap
            Bitmap bitmap=drawable.getBitmap();
            //return Bitmap.createScaledBitmap(bitmap, 100, 100, false);
    //获取窗体的宽高,对不同分辨率的手机进行适配
            WindowManager manager = (WindowManager) context
                    .getSystemService(Context.WINDOW_SERVICE);
            Display display = manager.getDefaultDisplay();
            int width = display.getWidth();
            int height = display.getHeight();
            if (height < 480 || width < 320) {
                return Bitmap.createScaledBitmap(bitmap, 32, 32, false);
    
            }else {
                return Bitmap.createScaledBitmap(bitmap, 48, 48, false);
            }
    
        }
    
    }
    展开全文
  • file转bitmap File param = new File(); Bitmap bitmap= BitmapFactory.decodeFile(param.getPath());...drawablebitmap Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.mipmap.jcss_03 ...

    file转bitmap

    File param = new File();

     

    Bitmap bitmap= BitmapFactory.decodeFile(param.getPath());

    drawable转bitmap

     

    Bitmap    bmp = BitmapFactory.decodeResource(getResources(),R.mipmap.jcss_03 );

    url转bitmap

     

    Bitmap bitmap;
    public Bitmap returnBitMap(final String url){
    
        new Thread(new Runnable() {
            @Override
            public void run() {
                URL imageurl = null;
    
                try {
                    imageurl = new URL(url);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                try {
                    HttpURLConnection conn = (HttpURLConnection)imageurl.openConnection();
                    conn.setDoInput(true);
                    conn.connect();
                    InputStream is = conn.getInputStream();
                    bitmap = BitmapFactory.decodeStream(is);
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    
        return bitmap;
    }

     

    方法二:

    public Bitmap getBitmap(String url) {
        Bitmap bm = null;
        try {
            URL iconUrl = new URL(url);
            URLConnection conn = iconUrl.openConnection();
            HttpURLConnection http = (HttpURLConnection) conn;
    
            int length = http.getContentLength();
    
            conn.connect();
            // 获得图像的字符流
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is, length);
            bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();// 关闭流
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return bm;
    }

     

    可配合前台线程显示

     

    private Handler mHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case REFRESH_COMPLETE:
                    myheadimage.setImageBitmap(bitmap);//显示
                    break;
            }
        }
    };
    String imageUrl = "http://www.pp3.cn/uploads/201511/2015111212.jpg";
    bitmap= returnBitMap(imageUrl);
    mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 1000);

    bitmap转file

    private  String SAVE_PIC_PATH = Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)
            ? Environment.getExternalStorageDirectory().getAbsolutePath() : "/mnt/sdcard";//
    
    private  String SAVE_REAL_PATH = SAVE_PIC_PATH + "/good/savePic";//保存的确

     

    saveFile(bmp, System.currentTimeMillis() + ".png");
      //保存方法
        private void saveFile(Bitmap bm, String fileName) throws IOException {
            String subForder = SAVE_REAL_PATH;
            File foder = new File(subForder);
            if (!foder.exists()) foder.mkdirs();
    
            File myCaptureFile = new File(subForder, fileName);
            Log.e("lgq","图片保持。。。。wwww。。。。"+myCaptureFile);
            ends = myCaptureFile.getPath();
            if (!myCaptureFile.exists()) myCaptureFile.createNewFile();
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
            bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);
            bos.flush();
            bos.close();
    //        ToastUtil.showSuccess(getApplicationContext(), "已保存在/good/savePic目录下", Toast.LENGTH_SHORT);
            //发送广播通知系统
            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri uri = Uri.fromFile(myCaptureFile);
            intent.setData(uri);
            this.sendBroadcast(intent);
        }

    bitmap与byte[]之间相互转换

     

    Android 图片压缩,bitmap与byte[]之间相互转换:https://blog.csdn.net/meixi_android/article/details/89921090

    展开全文
  • Bitmap drawable2Bitmap(Drawable drawable) {  if (drawable instanceof NinePatchDrawable) {  NinePatchDrawable npd = (NinePatchDrawable) drawable;  Bitmap output_bitmap = Bitmap.createBitmap(npd


      if (drawable instanceof NinePatchDrawable) {
       NinePatchDrawable npd = (NinePatchDrawable) drawable;
       Bitmap output_bitmap = Bitmap.createBitmap(npd.getIntrinsicWidth(), npd.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
          Canvas canvas = new Canvas(output_bitmap);
          npd.draw(canvas);

          return output_bitmap;

      } else {
       BitmapDrawable bd = (BitmapDrawable) drawable;
       return bd.getBitmap();
      }
     

    展开全文
  • // 将Drawable转化Bitmap public static Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); B
  • Android图片 将Drawable转化Bitmap

    千次阅读 2013-07-05 18:50:22
    public static Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, draw
  • private static Bitmap drawableToBitmap(Drawable drawable) { if (drawable == null) { return null; } Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), ....
  • drawablebitmap

    2014-08-09 22:36:16
    从资源中获取BitmapBitmap bytebyte BitmapBitmap缩放将Drawable转化Bitmap获得圆角图片 获得带倒影的图片 三Drawable Bitmap转换成DrawableDrawable缩放牺牲图片质量为代价将图片进行放缩创建临时空间 1...
  • drawable 转化bitmap: BitmapDrawable bd = (BitmapDrawable) drawable;  bitmap = bd.getBitmap(); bitmap 转化drawable:  Bitmap bm=xxx;  BitmapDr
  • DrawableBitmap和数组的互相转化 =========================================================================== 数组和Bitmap之间的转换 数组转换成Bitmap int[] byteArray; //byteArray就是存着...
  • http://dyh7077063.iteye.com/blog/970672
  • Drawable转为Bitmap

    2016-04-07 14:03:36
    private Bitmap drawable2bitmap(Drawable drawable) { if(drawable instanceof BitmapDrawable) { bitmapDrawable bd = (BitmapDrawable)drawable; return bd.getBitmap(); } int w
  • * Drawable转化Bitmap */ public static Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bit
  • DrawableBitmap转换

    2013-09-21 13:21:31
    一、BitmapDrawable Bitmap bm=xxx; //xxx根据你的情况获取 BitmapDrawable bd=new BitmapDrawable(bm); 因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。 二、 DrawableBitmap 转...
  • <br />Android中几种图像特效处理的小技巧,比如圆角,倒影,还有就是图片缩放,Drawable转化Bitmap,Bitmap转化为Drawable等等       大家好,这一节给大家分享的是Android中几种图像特效...
  • Drawable 转换为 Bitmap Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.emoji_0000); Bitmap 转换为 Drawable Drawable bitmapDrawable = new BitmapDrawable(getResources(),bitmap...
  • activity之间传递drawablebitmap)图片
  • Android常用的DrawableBitmap之间的转化方法

    万次阅读 多人点赞 2016-11-07 18:45:02
    bitmapDrawable间的区别: Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565、RGB888。作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低。我们理解为一种存储对象...
  • int arrowRes = R.drawable.bubble_arrow_light; Bitmap source = BitmapFactory.decodeResource(context.getResources(), arrowRes);
  • drawable转为bitmap对象

    2016-11-07 18:16:39
    Drawable对象转为Bitmap对象 private static Bitmap getBitmap(Drawable drawable) { //获取drawable高宽 int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight();
  • 1、Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable),我们根据画图的需求,创建相应的可画对象 2、Canvas画布,绘图的...
  • Android DrawableBitmap、byte、灰度 之间的转换

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,495
精华内容 2,198
关键字:

drawable转化bitmap