当前位置:首页 » 安卓系统 » android绘制bitmap

android绘制bitmap

发布时间: 2022-05-05 20:10:01

㈠ android的canvas如何转换为一张bitmap(位图)

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
下面再加上你要画的方框就行了,画完后可以直接使用bitmap对象,因为就是直接在bitmap上画的,将bitmap转换成.png或者.jpg格式图片后,就能放到gridview中使用了。

㈡ 谁能帮我详细讲讲android里的Bitmap的用法啊,结合Canvas和Drawable,谢了

Bitmap:表示绘制图像的点阵(矩阵),绘制的目的地、目标
canvas画布:持有绘图方法的对象(绘制动作)
例如:
//从drawable(在res目录下)里的图片转到输入流
InputStream is = context.getResources().openRawResource(R.drawable.app_sample_code)
//将输入流解码为bitmap对象
mBitmap = BitmapFactory.decodeStream(is);
//然后,在view的onDraw中将此bitmap对象绘制到屏幕的某一位置
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);

Paint p = new Paint();
float y = 10;

p.setColor(Color.RED);
canvas.drawBitmap(mBitmap, 10, y, p);
y += mBitmap.getHeight() + 10;
canvas.drawBitmap(mBitmap2, 10, y, p);
y += mBitmap2.getHeight() + 10;
p.setShader(mShader);
canvas.drawBitmap(mBitmap3, 10, y, p);
}

㈢ android 能在bitmap上绘制圆吗

能,这是往图片(图片转为Bitmap)上写入文字、图片,你换成画圆就是得了。
/**
* 往图片上写入文字、图片等内容
*/
private void drawNewBitmap(String str) {
Bitmap photo = BitmapFactory.decodeResource(this.getResources(),R.drawable.introce_first);

int width = photo.getWidth();
int hight = photo.getHeight();

Bitmap bitmap = Bitmap.createBitmap(width, hight, Bitmap.Config.ARGB_8888); // 建立一个空的BItMap
Canvas canvas = new Canvas(bitmap);// 初始化画布绘制的图像到icon上

Paint photoPaint = new Paint(); // 建立画笔
photoPaint.setDither(true); // 获取跟清晰的图像采样
photoPaint.setFilterBitmap(true);// 过滤一些

Rect src = new Rect(0, 0, photo.getWidth(), photo.getHeight());// 创建一个指定的新矩形的坐标
Rect dst = new Rect(0, 0, width, hight);// 创建一个指定的新矩形的坐标
canvas.drawBitmap(photo, src, dst, photoPaint);// 将photo 缩放或则扩大到
// dst使用的填充区photoPaint

Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);// 设置画笔
textPaint.setTextSize(30.0f);// 字体大小
textPaint.setTypeface(Typeface.DEFAULT_BOLD);// 采用默认的宽度
textPaint.setColor(Color.BLACK);// 采用的颜色
canvas.drawText(str, 200, 200, textPaint);// 绘制上去字,开始未知x,y采用那只笔绘制
canvas.drawBitmap(BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher), 100, 100, textPaint);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
iv.setBackgroundDrawable(new BitmapDrawable(this.getResources(), bitmap));
saveMyBitmap(bitmap,"test1");
}

㈣ Android开发里怎么在surfaceView里给Bitmap对象添加Animation动画

你好!
在run()方法里添加
draw()方法,在draw()方法里绘制,bitmap绘制成动画,你首先需要几张动作的图,然后按照计时器的方式每次画不同的图,连接起来就是一个动画了,比如有三张图把,先设置计时器
int
count
=
0
;
count++;
if(count
<
30){
canvas.drawBitmap();
画第一张图
}
if(count
<
50){
画第二张图
}
。。。大概就是这样
细节你自己琢磨把
仅代表个人观点,不喜勿喷,谢谢。

㈤ Android的drawbitmap绘制图片的位置与缩放问题

MainActivity.java

public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new MainLayout(this));
}
}
class MainLayout extends RelativeLayout
{
public MainLayout(Context context)
{
super(context);
setWillNotDraw(false);
}
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
bitmap = Bitmap.createScaledBitmap(bitmap, 854, 480, true);
canvas.drawBitmap
(
bitmap,
null,
new Rect(0, 0, 854, 480),
null
);
}
}

希望能够帮助到你,望采纳!

㈥ android中drawBitMap绘制函数中的参数

表示行扫描的宽度。

㈦ android怎样将canvas绘制的图形保存到bitmap中

可以用Bitmap.compress函数来把Bitmap对象保存成PNG或JPG文件,然后可以用BitmapFactory把文件中的数据读进来再生成Bitmap对象。
保存的代码大概类似于这样:
try {
FileOutputStream out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
具体的可以去查Bitmap和BitmapFactory的帮助文档。

㈧ android怎么生成bitmap

1、

[java] view plain
public Bitmap convertViewToBitmap(View view){

Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
Bitmap.Config.ARGB_8888);
//利用bitmap生成画布
Canvas canvas = new Canvas(bitmap);

//把view中的内容绘制在画布上
view.draw(canvas);

return bitmap;
}

2、

[java] view plain
/**
* save view as a bitmap
*/
private Bitmap saveViewBitmap(View view) {
// get current view bitmap
view.setDrawingCacheEnabled(true);
view.buildDrawingCache(true);
Bitmap bitmap = view.getDrawingCache(true);

Bitmap bmp = plicateBitmap(bitmap);
if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); bitmap = null; }
// clear the cache
view.setDrawingCacheEnabled(false);
return bmp;
}

public static Bitmap plicateBitmap(Bitmap bmpSrc)
{
if (null == bmpSrc)
{ return null; }

int bmpSrcWidth = bmpSrc.getWidth();
int bmpSrcHeight = bmpSrc.getHeight();

Bitmap bmpDest = Bitmap.createBitmap(bmpSrcWidth, bmpSrcHeight, Config.ARGB_8888); if (null != bmpDest) { Canvas canvas = new Canvas(bmpDest); final Rect rect = new Rect(0, 0, bmpSrcWidth, bmpSrcHeight);

canvas.drawBitmap(bmpSrc, rect, rect, null); }

return bmpDest;
}

㈨ Android 画板画bitmap的时候怎么指定绘画时的起始位置

drawbitmap方法 可指定top left参数,这两个参数就是代表bitmap的左顶点,即起始位置 也可指定rect参数,指定bitmap的大小和位置,具体请查看api

热点内容
编程猫知乎 发布:2025-05-15 02:18:00 浏览:631
服务器转接搭建 发布:2025-05-15 02:12:50 浏览:518
编译好的内核如何升级另一台主机 发布:2025-05-15 02:00:06 浏览:759
弹反脚本 发布:2025-05-15 01:58:24 浏览:587
安卓按键大师怎么用 发布:2025-05-15 01:54:12 浏览:688
手机ea服务器连不上怎么办 发布:2025-05-15 01:35:03 浏览:451
数据库数据插入语句 发布:2025-05-15 01:30:01 浏览:872
js是无需编译直接运行吗 发布:2025-05-15 01:28:30 浏览:477
android文件夹重命名 发布:2025-05-15 01:13:50 浏览:482
cns脚本 发布:2025-05-15 01:13:38 浏览:723