我有一個帶有背景圖像的ImageView。 ImageView的大小以屏幕的百分比爲單位進行編程。該視圖位於RelativeLayout中,位於它的中心。我想要的是使其可繪製。我希望能夠用手指畫出它(就像我們小時候在油漆中畫廢話一樣)。另外,當我移動手指時,我想要立即繪製路徑。你能給我一個如何去做的例子嗎?Android ImageView如何繪製路徑
0
A
回答
1
有繪製應用一些很好的參考,用少量的谷歌搜索發現:
簡單的應用程序,以獲得良好的溼手指/容易實現: http://v4all123.blogspot.com/2013/11/simple-drawing-example-in-android.html
比較複雜,但很詳盡的解釋: http://code.tutsplus.com/tutorials/android-sdk-create-a-drawing-app-touch-interaction--mobile-19202
無論使用的是ImageView的,但我敢肯定,你可以容納切換視圖類型
0
您將不得不重寫ImageView的onTouchEvent
和onDraw
調用。獲取用戶在onTouchEvent
中的觸摸位置,並畫到ImageView
的canvas
。 看到這裏的示例 - paint canvas android
1
只需拿GestureOverlayView並將您的圖像設置爲此OverlayView的背景。
<android.gesture.GestureOverlayView
android:id="@+id/signaturePad"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="@color/white"
android:eventsInterceptionEnabled="true"
android:fadeEnabled="false"
android:gestureColor="@color/black"
android:gestureStrokeLengthThreshold="0.1"
android:gestureStrokeType="multiple"
android:orientation="vertical" >
</android.gesture.GestureOverlayView>
以及用於從GestureOverlayView保存圖像的功能。
try {
GestureOverlayView gestureView = (GestureOverlayView) findViewById(R.id.signaturePad);
gestureView.setDrawingCacheEnabled(true);
Bitmap bm = Bitmap.createBitmap(gestureView.getDrawingCache());
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "signature.png");
f.createNewFile();
FileOutputStream os = new FileOutputStream(f);
os = new FileOutputStream(f);
//compress to specified format (PNG), quality - which is ignored for PNG, and out stream
bm.compress(Bitmap.CompressFormat.PNG, 100, os);
os.close();
} catch (Exception e) {
Log.v("Gestures", e.getMessage());
e.printStackTrace();
}
關注該Example
相關問題
- 1. Android繪製路徑
- 2. Android - 繪製路徑
- 3. 如何繪製路徑到Android中
- 4. Android ImageView繪製
- 5. Android - 可繪製路徑
- 6. Android:繪製多個路徑
- 7. 在android中繪製路徑?
- 8. Mapview繪製路徑路徑
- 9. 如何繪製此路徑?
- 10. 繪製路徑
- 11. 繪製路徑 - iPhone
- 12. 在android地圖上繪製路徑
- 13. Android可繪製路徑爲空
- 14. Android - 保存路徑並稍後繪製
- 15. Android:在路徑中隨機繪製框
- 16. Android路徑繪製動態線
- 17. 在Android中逐漸繪製的路徑
- 18. Canvas在android中繪製路徑
- 19. 從Lat/Long繪製路徑
- 20. 的Android只繪製的ImageView
- 21. Android:繪製畫布到ImageView
- 22. 如何實時繪製MapKit路徑(iOS7 +)
- 23. 如何使用位圖繪製路徑?
- 24. 如何繪製帶邊框的路徑?
- 25. 如何在WPF中繪製此路徑?
- 26. 如何繪製svg路徑動畫
- 27. 如何繪製具有可用lat長度的路徑路徑android
- 28. Android Canvas在路徑指向視圖時沒有繪製路徑
- 29. Android:從SD卡上的已知路徑將圖像繪製到ImageView上
- 30. Android路徑:合併幾條路徑並在合併路徑上繪製文本