綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 如何在imageview上畫圖

[複製連結] 查看: 4149|回覆: 1|好評: 0
跳轉到指定樓層
樓主
30cm | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2013-4-11 19:36

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
如題
在程式中載入圖片並用ImageView顯示
但後面想讓使用者能在上面畫畫加一些東西
那如何在上面畫畫
當然我知道要用Canvas和Paint來實現
然後重作onDraw的方法

「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
iamjason008 | 收聽TA | 只看該作者
發表於 2013-4-15 15:58
參考一下這裡
http://www.eoeandroid.com/thread-264349-1-1.html

1.Create a new image bitmap and attach a brand new canvas to it so that the bitmap and the canvas use the same coordinate system.
2.Draw the image bitmap into the canvas.
3.Draw everything else you want into the canvas (the rectangles in my case).
4.Attach the canvas to the ImageView.

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;

ImageView myImageView = ...
Bitmap myBitmap = ...
Paint myRectPaint = ...
int x1 = ...
int y1 = ...
int x2 = ...
int y2 = ...

//Create a new image bitmap and attach a brand new canvas to it
Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565);
Canvas tempCanvas = new Canvas(tempBitmap);

//Draw the image bitmap into the cavas
tempCanvas.drawBitmap(myBitmap, 0, 0, null);

//Draw everything else you want into the canvas, in this example a rectangle with rounded edges
tempCanvas.drawRoundRect(new RectF(x1,y1,x2,y2), 2, 2, myPaint);

//Attach the canvas to the ImageView
myImageView.setImageDrawable(new BitmapDrawable(getResources(), tempBitmap));

評分

參與人數 1幫助 +1 收起 理由
ploglin + 1

查看全部評分

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則