2017-06-02 1 views
-1

私はアンドロイドプロジェクトのような図面を作成するためにアンドロイドキャンバスクラスを使用する必要があります。しかし、私はアンドロイドアプリを開発していないだけで、簡単なコマンドラインスクリプトは、図面の束を生成します。今私はjavas Graphics2Dが私のニーズを満たしていないことが分かった。だから私はどのようにEclipseのJavaプロジェクトでアンドロイドキャンバスのグラフィックスを使用することができますか?Java:android.graphics.CanvasをAndroid Javaプロジェクトで使用する方法

私はキャンバスを作成し、drawArc drawLineみたいに描きたい...そして、ビットマップとして保存

+0

そのクラスはAndroid以外のGUIで描画しませんが、 –

+0

@ cricket_007 GUIを描画したくありません。キャンバスを作成しdrawArc drawLineのように描画したい場合は、ビットマップとして保存してください。 – Michal

+0

Graphics2Dはすでにこれを行うことができます。 https://stackoverflow.com/questions/8202253/saving-a-java-2d-graphics-image-as-png-file –

答えて

0

イムないあなたが何を意味するか確認してください、私はあなたがやろうとしているものだと思うが、ユーザがあるということですシェイプを入れることができるか、自動的にシェイプを作成します。あなたは、第2のリンク:)

https://examples.javacodegeeks.com/android/core/graphics/canvas-graphics/android-canvas-example/

https://developer.android.com/reference/android/graphics/Canvas.html

void drawOval(float left, float top, float right, float bottom, Paint paint) 

か何かこの

などは、以下の異なる形状を設定することができ、このための出発点として、うまくいけば提供されるリンクを使用することができます
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) { 
if (scaleBitmapImage == null) { 
    return null; 
} 
int sourceWidth = scaleBitmapImage.getWidth(); 
int sourceHeight = scaleBitmapImage.getHeight(); 
int targetWidth = Math.min(sourceWidth, sourceHeight); 
int targetHeight = targetWidth; 
Bitmap targetBitmap = Bitmap.createBitmap(
     targetWidth, 
     targetHeight, 
     Bitmap.Config.ARGB_8888 
     ); 

Canvas canvas = new Canvas(targetBitmap); 
Path path = new Path(); 
path.addCircle(
     ((float) targetWidth - 1)/2, 
     ((float) targetHeight - 1)/2, 
     Math.min(((float) targetWidth), ((float) targetHeight))/2, 
     Path.Direction.CCW 
     ); 

canvas.clipPath(path); 
Bitmap sourceBitmap = scaleBitmapImage; 
canvas.drawBitmap(
     sourceBitmap, 
    new Rect(0, 0, sourceBitmap.getWidth(), 
    sourceBitmap.getHeight()), 
    new Rect(0, 0, targetWidth, targetHeight), 
    null 
     ); 
return targetBitmap; 
} 

出典:http://www.programcreek.com/java-api-examples/index.php?api=android.graphics.Canvas

関連する問題