`
bashenmail
  • 浏览: 226991 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android图片总结

阅读更多

图片缩放:

public static Drawable resizeImage(Drawable d, int w, int h) {

        // load the origial Bitmap

        Bitmap BitmapOrg = ((BitmapDrawable) d).getBitmap();

        int width = BitmapOrg.getWidth();

        int height = BitmapOrg.getHeight();

        int newWidth = w;

        int newHeight = h;

        // calculate the scale

        float scaleWidth = ((float) newWidth) / width;

        float scaleHeight = ((float) newHeight) / height;

        // create a matrix for the manipulation

        Matrix matrix = new Matrix();

        // resize the Bitmap

        matrix.postScale(scaleWidth, scaleHeight);

        Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,

                        height, matrix, true);

        // make a Drawable from Bitmap to allow to set the Bitmap

        // to the ImageView, ImageButton or what ever

        return new BitmapDrawable(resizedBitmap);

	}

 

public static Drawable resizeImage(Bitmap bitmap, int w, int h) {



                // load the origial Bitmap

                Bitmap BitmapOrg = bitmap;



                int width = BitmapOrg.getWidth();

                int height = BitmapOrg.getHeight();

                int newWidth = w;

                int newHeight = h;



                // calculate the scale

                float scaleWidth = ((float) newWidth) / width;

                float scaleHeight = ((float) newHeight) / height;



                // create a matrix for the manipulation

                Matrix matrix = new Matrix();

                // resize the Bitmap

                matrix.postScale(scaleWidth, scaleHeight);

                // if you want to rotate the Bitmap

                // matrix.postRotate(45);



                // recreate the new Bitmap

                Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,

                                height, matrix, true);



                // make a Drawable from Bitmap to allow to set the Bitmap

                // to the ImageView, ImageButton or what ever

                return new BitmapDrawable(resizedBitmap);



        }

 图片写字:

/**
	 * 图片上画字
	 * */
	private Bitmap drawTextAtBitmap(Bitmap bitmap,String text){
		
		int x = bitmap.getWidth();
		
		int y = bitmap.getHeight();
		
		// 创建一个和原图同样大小的位图
		Bitmap newbit = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
		
		Canvas canvas = new Canvas(newbit);
		
		Paint paint = new Paint();
		
		// 在原始位置0,0插入原图
		canvas.drawBitmap(bitmap, 0, 0, paint);
		
		paint.setColor(Color.parseColor("#dedbde"));
		
		paint.setTextSize(20);
		
		// 在原图指定位置写上字
		canvas.drawText(text, 53 , 30, paint);
		
		canvas.save(Canvas.ALL_SAVE_FLAG);
		
		// 存储
		canvas.restore();
		
		return newbit;
	}

 

分享到:
评论
3 楼 elena_java 2010-09-21  
字串太长不能自动换行怎么办?!
2 楼 bashenmail 2010-08-18  
jn615 写道
return newbit; 
之后呢?如何处理呀?我想知道怎么把newbit写道文件夹下


Bitmap 有个这个方法:
boolean compress(Bitmap.CompressFormat format, int quality, OutputStream stream)

其中stream 即是你的输出流

参数:
format The format of the compressed image
quality Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting
stream The outputstream to write the compressed data.
File f = new File("your path");
FileOutputStream output = new FileOutputStream(f);
//mBitmap 即为 return newbit
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();

异常请自己捕捉,我就不写了。
1 楼 jn615 2010-08-16  
return newbit; 
之后呢?如何处理呀?我想知道怎么把newbit写道文件夹下

相关推荐

    android图片处理总结

    android图片处理总结,总结了一些关于安装的图片处理方法,欢迎借鉴

    Android图片浏览器报告[参照].pdf

    "Android图片浏览器报告" Android图片浏览器是一种移动应用程序,旨在提供一个便捷的图片浏览体验。通过实现一个完整的软件,体验软件项目开发的工作流程,加深对相关理论知识的理解,提高实际分析设计能力。 在...

    Android图片上传服务器

    自己总结的关于Android上传图片到服务器的一个小demo

    Android上传图片到服务器

    自己总结的一个关于Android上传图片到服务器的一个小demo

    Android技术总结.doc

    Android应用程序的资源文件包括布局文件、字符串资源、图片资源等。这些资源文件可以被应用程序引用和使用。 3.2 asset文件 asset文件是Android应用程序的资源文件,用于存储应用程序的数据和配置信息。 四、...

    Android 三大图片缓存原理、特性对比

    Android 三大图片缓存原理、特性对比

    Android工作总结

    自己的工作上的一些总结,之后会不断更新的 现在这个是有关Opengl为啥有时候贴图不显示 和Android获得剩余内存的问题

    android Bitmap用法总结

    android Bitmap用法总结 Bitmap用法总结 1、Drawable → Bitmap public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable....

    Android ListView控件显示数据库中图片

    Android ListView 控件显示数据库中...本文总结了 Android ListView 控件显示数据库中图片的过程,涉及到 SimpleAdapter、ViewBinder、数据库操作、ListView 控件的点击事件、图片的显示等知识点,希望对读者有所帮助。

    Android图片压缩(质量压缩和尺寸压缩)

    在网上调查了图片压缩的方法并实装后,大致上可以认为有两类压缩:...android图片压缩总结 总 结来看,图片有三种存在形式:硬盘上时是file,网络传输时是stream,内存中是stream或bitmap,所谓的质量压缩,它其实只能

    android 图片多选

    自己写的demo,总结一下关于拍照本地图片多选。实现文件夹按图片修改时间排序,点击查看大图

    android 网络图片缓存策略

    在android中,获取网络图片进行缓存是必须的,但是如果你的缓存策略不够好的话就会内存溢出,今天我总结一下我自己的看法,并做了demo。用到了线程池来控制线程,根据你手机的cpu的个数来确定你线程池中线程数的大小...

    Android高效压缩图片不失真的方法总结

    详情请移步:http://blog.csdn.net/alfred_c/article/details/50542741

    Android 总结项目

    popupWindow、对话框、元素切换场景动画、图片打点、RN与Android交互、美团界面实现

    Android 实例实现自定义Camera和前后置摄像头切换以及图片缩小放大预览

    在具体实现代码之前,我们先来了解一下Android api对实现自定义Camera的介绍。 根据api的介绍,对于Camera应用可以简单总结以下几个步骤。 1.检查Camera是否存在,并在AndroidManifest.xml中赋予相关的权限; 2....

    android图片与内存的关系

    自己对android中图片与内存消耗的一点总结!

    《Android应用开发》个人总结报告.doc

    《Android应用开发》个人总结报告 刚开始接触Android感觉到它很有意思,在界面开发上和web也可以形成了相通的架构 ,更加方便,视觉上也是非常的酷,在前期我通过的大量的Android SDK开发范例大全中的例子以及...

Global site tag (gtag.js) - Google Analytics