當前位置:首頁 » 安卓系統 » 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-14 22:36:27 瀏覽:633
wemall微商城源碼 發布:2025-05-14 22:15:20 瀏覽:804
隆地優選交易密碼是什麼 發布:2025-05-14 21:53:23 瀏覽:96
強酸強鹼存儲櫃 發布:2025-05-14 21:45:16 瀏覽:565
車輛參數配置包括什麼 發布:2025-05-14 21:31:03 瀏覽:164
怎麼引入安卓項目 發布:2025-05-14 21:26:39 瀏覽:825
游戲輔編程 發布:2025-05-14 21:18:49 瀏覽:688
三菱plc一段二段密碼什麼意思 發布:2025-05-14 21:17:16 瀏覽:529
電腦開機密碼忘記了怎麼破解 發布:2025-05-14 21:09:40 瀏覽:57
pythondict格式 發布:2025-05-14 21:09:38 瀏覽:887