मैं एक कैनवास ड्राइंग ऑपरेशन को एक चाप के आकार के वेज पर क्लिप करने की कोशिश कर रहा हूं। हालांकि, मुझे कैनवास के क्लिपिंग पथ को सेट करने के बाद इच्छित परिणाम नहीं मिल रहा है।कैनवास.क्लिपपाथ (पथ) अपेक्षित के रूप में क्लिपिंग नहीं कर रहा है
उदाहरण के लिए, यहाँ मैं क्या कर रहा है:
path.reset();
//Move to point #1
path.moveTo(rect.centerX(), rect.centerY());
//Per the documentation, this will draw a connecting line from the current
//position to the starting position of the arc (at 0 degrees), add the arc
//and my current position now lies at #2.
path.arcTo(rect, 0, -30);
//This should then close the path, finishing back at the center point (#3)
path.close();
यह काम करता है, और जब मैं बस इस पथ (canvas.drawPath(path, paint)
) आकर्षित के रूप में ऊपर दिखाए गए कील खींचता है। हालांकि, जब मैं कैनवास के कतरन पथ के रूप में इस पथ सेट और इसे में आकर्षित:
//I've tried it with and without the Region.Op parameter
canvas.clipPath(path, Region.Op.REPLACE);
canvas.drawColor(Color.BLUE);
मैं करने के निम्न परिणाम के बजाय (कील सिर्फ संदर्भ दिखाने के लिए छोड़ दिया जाता है):
तो यह Path
के बाउंडिंग रेक्ट पर क्लिप करने लगता है, और Path
स्वयं नहीं। कोई विचार क्या हो रहा है यहाँ?
संपादित करें बस एक अपडेट के रूप में, मुझे ऐसा करने का एक और अधिक प्रभावी तरीका मिला है जो हार्डवेयर त्वरण की अनुमति देता है। सबसे पहले, एक पूर्णस्क्रीन बिटमैप में पूरी छवि (जिसे आप क्लिपिंग करेंगे) खींचें।
drawMyBitmap(bitmap);
Shader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setShader(shader);
@Override
public void onDraw(Canvas canvas) {
canvas.drawArc(rect, //The rectangle bounding the circle
startAngle, //The angle (CW from 3 o'clock) to start
sweepAngle, //The angle (CW from 3 o'clock) of the arc
true, //Boolean of whether to draw a filled arc (wedge)
paint //The paint with the shader attached
);
}
आप उपयोग कर रहे हैं
एक
Paint
बनाएं एचसी या ऊपर या अन्यथा हार्डवेयर त्वरण का उपयोग कर? http://developer.android.com/guide/topics/graphics/hardware-accel.html। यदि ऐसा है, तो क्लिपपैथ असमर्थित और समस्याग्रस्त है। – Simon@ सिमॉन: हे भगवान! हे। अफसोस की बात है कि मैं इस दस्तावेज का इस सप्ताह बहुत कुछ जिक्र कर रहा हूं, लेकिन मैंने इसे पूरी तरह से अनदेखा कर दिया। एचडब्ल्यू एक्सेल को अक्षम करने से पूरी तरह से काम किया! यदि आप इसे उत्तर के रूप में पोस्ट करेंगे तो मैं इसे स्वीकार करूंगा। तुम एक lifesaver हो! – kcoppock
मदद करने में खुशी हुई। सौभाग्य। – Simon