当前位置:首页 » 安卓系统 » androidbitmap背景

androidbitmap背景

发布时间: 2022-06-25 04:17:31

⑴ android中paint如何设置背景图片

1.创建一个背景图大小的Bitmap Bitmap bitmap=Bitmap.createBitmap(X, Y, Config.ARGB_8888);

2.Canvas canvas=new Canvas(bitmap); //创建画布Paint paint=new Paint(); //画笔

3。在canvas上画东西取得背景图片的Bitmap canvas.drawBitmap(backgroundBitmap, Rect , Rect , paint);
按照上面的步骤就可以设置背景图片了

⑵ android createBitmap,如何设置背景色

此方法是根据int[] colors色素组创建Bitmap,你可以到这里看一下:http://blog.csdn.net/gaomatrix/article/details/6532468

⑶ Android开发,动态设置Activity的layout背景图片问题

Bitmap img = BitmapFactory.decodeFile(BackgroundPath);

执行这行代码的时候,抛出的异常,估计是报内存溢出
原因很简单,Bitmap 是用字节来代码像素点的
如果你的图片非常大,那么android需要创建一个非常大的数组来生成bitmap对象
这时候就会抛出异常
建议你创建Bitmap前,先测试一下图片的大小,把图片的大小压缩成屏蔽的大小
再用来做layout的Background

⑷ 如何实现Android 布局背景模糊化处理

在模仿 IOS 密码输入页面的时候发现其背景有模糊处理,于是了解了一下并记录下来,以便使用.在Android 中具体实现方法如下

查考 http://www.cnblogs.com/lipeil/p/3997992.html

java代码
private void applyBlur() {

// 获取壁纸管理器
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this.getContext());
// 获取当前壁纸
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
// 将Drawable,转成Bitmap
Bitmap bmp = ((BitmapDrawable) wallpaperDrawable).getBitmap();

blur(bmp);
}

下面之所以要进行small 和big的处理,是因为仅仅靠ScriptIntrinsicBlur
来处理模式,不能到达更模式的效果,如果需要加深模式效果就需要先把背景图片缩小,在处理完之后再放大.这个可以使用Matrix
来实现,而且这样可以缩短模糊化得时间

Java代码
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void blur(Bitmap bkg) {
long startMs = System.currentTimeMillis();
float radius = 20;

bkg = small(bkg);
Bitmap bitmap = bkg.(bkg.getConfig(), true);

final RenderScript rs = RenderScript.create(this.getContext());
final Allocation input = Allocation.createFromBitmap(rs, bkg, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.To(bitmap);

bitmap = big(bitmap);
setBackground(new BitmapDrawable(getResources(), bitmap));
rs.destroy();
Log.d("zhangle","blur take away:" + (System.currentTimeMillis() - startMs )+ "ms");
}

private static Bitmap big(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.postScale(4f,4f); //长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return resizeBmp;
}

private static Bitmap small(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.postScale(0.25f,0.25f); //长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return resizeBmp;
}

⑸ android 在Java代码中,我调用一个函数后返回Bitmap图,想将它设为背景,每次调用setbackground都出错

一般情况下,错误信息中都会含带错误出现的页面位置,比如多少行,那么就到你部署的程序的服务器中查看work下面编译成java代码以后的jsp页面。用记事本或者notepad++打开,定位到那一行,就可以确定是哪一句的问题。
可以在jsp页面中的服务器脚本中写System.out.println("123");看是否输出(此处的System.out.println("123")尽量多写几行,在你认为有可能发生错误的一段内也可以),逐渐缩小范围。
最后一种就是:空指针异常都是由于“对象点”引起的,这种写法的地方都值得怀疑一下,尤其是传值过来的。

⑹ 怎么实现Android 布局背景模糊化处理

在模仿 IOS 密码输入页面的时候发现其背景有模糊处理,于是了解了一下并记录下来,以便使用.在Android 中具体实现方法如下
private void applyBlur() {

// 获取壁纸管理器
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this.getContext());
// 获取当前壁纸
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
// 将Drawable,转成Bitmap
Bitmap bmp = ((BitmapDrawable) wallpaperDrawable).getBitmap();

blur(bmp);
}

下面之所以要进行small 和big的处理,是因为仅仅靠ScriptIntrinsicBlur 来处理模式,不能到达更模式的效果,如果需要加深模式效果就需要先把背景图片缩小,在处理完之后再放大.这个可以使用Matrix 来实现,而且这样可以缩短模糊化得时间
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void blur(Bitmap bkg) {
long startMs = System.currentTimeMillis();
float radius = 20;

bkg = small(bkg);
Bitmap bitmap = bkg.(bkg.getConfig(), true);

final RenderScript rs = RenderScript.create(this.getContext());
final Allocation input = Allocation.createFromBitmap(rs, bkg, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.To(bitmap);

bitmap = big(bitmap);
setBackground(new BitmapDrawable(getResources(), bitmap));
rs.destroy();
Log.d("zhangle","blur take away:" + (System.currentTimeMillis() - startMs )+ "ms");
}

private static Bitmap big(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.postScale(4f,4f); //长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return resizeBmp;
}

private static Bitmap small(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.postScale(0.25f,0.25f); //长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return resizeBmp;
}

⑺ Android 怎么用网上的图片设置ImageView背景

Android 用网上的图片设置ImageView背景可以使用如下方法:


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myimage);
ImageView image1 = (ImageView) findViewById(R.myImage.image);
//Bitmap bitmap = getLoacalBitmap(“/aa/aa.jpg”); //从本地取图片
Bitmap bitmap = getHttpBitmap(“http://blog.3gstdy.com/wp-content/themes/twentyten/images/headers/path.jpg”); //从网上取图片
image1 .setImageBitmap(bitmap); //设置Bitmap
}
/**
* 加载本地图片
* http://bbs.3gstdy.com
* @param url
* @return
*/
public static Bitmap getLoacalBitmap(String url) {
try {
FileInputStream fis = new FileInputStream(url);
return BitmapFactory.decodeStream(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
/**
* 从服务器取图片
*http://bbs.3gstdy.com
* @param url
* @return
*/
public static Bitmap getHttpBitmap(String url) {
URL myFileUrl = null;
Bitmap bitmap = null;
try {
Log.d(TAG, url);
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setConnectTimeout(0);
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}

⑻ 如何将android中两种bitmap叠加居中形成一个比较漂亮的图

常用场景:给桌面图标添加底盘背景图 public Bitmap addbackground4onlyicon(Resources r, Bitmap icon) { Bitmap b1 = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap1);; Bitmap b2 = icon; if (!b1.isMutable()) { //设置图片为背景为透明 b1 = b1.(Bitmap.Config.ARGB_8888, true); } Paint paint = new Paint(); Canvas canvas = new Canvas(b1); int b1w = b1.getWidth(); int b1h = b1.getHeight(); int b2w = b2.getWidth(); int b2h = b2.getHeight(); int bx = (b1w - b2w) / 2; int by = (b1h - b2h) / 2; canvas.drawBitmap(b2, bx, by, paint);//叠加新图b2 并且居中 canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); return b1; }

⑼ android bitmap使用时注意什么

一、 问题的背景和意义
在Android移动应用开发中,对Bitmap的不小心处理,很容易引起程序内存空间耗尽而导致的程序崩溃问题。比如我们常遇到的问题:
java.lang.OutofMemoryError: bitmap size exceeds VM budget.
导致该问题的出现,一般由以下几方面原因导致:
引动设备一般存储空间非常有限。当然不同设备分配给应用的内存空间是不同的。但相对不但提高的设备分辨率而言,内存的分配仍然是相对紧张的。
Bitmap对象常常占用大量的内存空间,比如:对于2592*1936的设备,如果采用ARGB_8888的格式加载图像,内存占用将达到19MB空间。
在Anroid App中经常用到ListView,ViewPager等控件,这些控件常会包含较大数量的图片资源。
二、 问题及场景分析
1 高效地加载大图片。
BitmapFactory类提供了一些加载图片的方法:decodeByteArray(), decodeFile(), decodeResource(), 等等。
为了避免占用较大内存,经常使用BitmapFactory.Options 类,设置inJustDecodeBounds属性为true。
//
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds =true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
为了避免java.lang.OutOfMemory 的异常,我们在真正decode图片之前检查它的尺寸,除非你确定这个数据源提供了准确无误的图片且不会导致占用过多的内存。
加载一个按比例缩小的版本到内存中。例如,如果把一个原图是1024*768 pixel的图片显示到ImageView为128*96 pixel的缩略图就没有必要把整张图片都加载到内存中。为了告诉解码器去加载一个较小的图片到内存,需要在你的BitmapFactory.Options 中设置 inSampleSize 为true 。例如, 一个分辨率为2048x1536 的图片,如果设置inSampleSize 为4,那么会产出一个大概为512x384的图片。加载这张小的图片仅仅使用大概0.75MB,如果是加载全图那么大概要花费12MB(假设bitmap的配置是ARGB_8888).
2 不要在主线程处理图片。

众所周知的问题,不再赘述。
注意两点:1. 为了保证使用的资源能被回收,建议使用WeakReference, 以应用内存内存紧张时,回收部分资源,保证程序进程不被杀死。
2. 避免异步任务的长时间耗时操作,在任务执行结束后,及时释放资源。
3 管理Bitmap内存。
在Android开发中,加载一个图片到界面很容易,但如果一次加载大量图片就复杂多了。在很多情况下(比如:ListView,GridView或ViewPager),能够滚动的组件需要加载的图片几乎是无限多的。
有些组件的child view在不显示时会回收,并循环使用,如果没有任何对bitmap的持久引用的话,垃圾回收器会释放你加载的bitmap。这没什么问题,但当这些图片再次显示的时候,要想避免重复处理这些图片,从而达到加载流畅的效果,就要使用内存缓存和本地缓存了,这些缓存可以让你快速加载处理过的图片。
3.1 内存缓存
内存缓存以牺牲内存的代价,带来快速的图片访问。LruCache类(API Level 4之前可以使用Support Library)非常适合图片缓存任务,在一个LinkedHashMap中保存着对Bitmap的强引用,当缓存数量超过容器容量时,删除最近最少使用的成员(LRU)。
注意:在过去,非常流行用SoftReference或WeakReference来实现图片的内存缓存,但现在不再推荐使用这个方法了。因为从Android 2.3 (API Level 9)之后,垃圾回收器会更积极的回收soft/weak的引用,这将导致使用soft/weak引用的缓存几乎没有缓存效果。顺带一提,在Android3.0(API Level 11)以前,bitmap是储存在native 内存中的,所以系统以不可预见的方式来释放bitmap,这可能会导致短时间超过内存限制从而造成崩溃。

⑽ gdi+的BITMAP或者IMAGE怎么设置背景色不要透明

在布局文件中,可以使用属性android:background="#00ffffff",在方法中使用view.setBackgroundColor(android.graphics.Color.parseColor("#00ffffff")); 在GrilView中注意,如果有子视图,子视图的背景设为透明才能使GrilView背景全部透明。

热点内容
roblox跑酷脚本怎么做 发布:2024-05-05 03:57:35 浏览:700
捷径清理缓存 发布:2024-05-05 03:57:35 浏览:477
ftputility哪里下载 发布:2024-05-05 03:47:13 浏览:999
雷凌运动版如何连接安卓手机导航 发布:2024-05-05 03:42:48 浏览:266
自动鬼使黑脚本 发布:2024-05-05 03:10:49 浏览:880
游戏脚本编程书籍推荐 发布:2024-05-05 02:59:13 浏览:72
编译器书籍推荐 发布:2024-05-05 02:57:02 浏览:56
电池存储温度 发布:2024-05-05 02:53:07 浏览:207
安卓在美国怎么下载 发布:2024-05-05 02:31:06 浏览:925
黑莓存储空间 发布:2024-05-05 02:19:50 浏览:275