2012-12-17 14 views
5

अब मुझे पता है कि कैसे एंड्रॉयड में एक GIF चित्र आकर्षित करने के लिए gif चित्र आकार बदलने के लिए कैसे, यहाँ कोड है:में एंड्रॉयड

public class GIFView extends View{   
private Movie movie; 
private InputStream is; 
private long moviestart; 
public GIFView(Context context) { 
    super(context); 
    is=getResources().openRawResource(R.drawable.anim_cerca); 
    movie=Movie.decodeStream(is); 
} 

@Override 
protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 
    long now=android.os.SystemClock.uptimeMillis(); 

    if (moviestart == 0) 
     moviestart = now; 

    int relTime = (int)((now - moviestart) % movie.duration()); 
    movie.setTime(relTime); 
    movie.draw(canvas,10,10); 
    this.invalidate(); 
} 

}

अंत में, movie.draw(canvas,x,y) कोड है , जहां x और y gif चित्र के लिए समन्वय है (x = left, y = top)। लेकिन मैं फिल्म की चौड़ाई और ऊंचाई कैसे बदल सकता हूं? शायद सही और निचले निर्देशांक दें, लेकिन कैसे, कहाँ? धन्यवाद!

+0

मुझे लगता है कि आप canvas.scale की कोशिश की है OnDraw विधि में इस कोड को जोड़ना है यहाँ एक ही समस्या थी()? –

+0

हाँ, मैंने कोशिश की, लेकिन कुछ भी नहीं बदला है। मेरा मतलब आकार में कुछ भी नहीं है, लेकिन तस्वीर चली गई, जब मैंने इस विधि को जोड़ा। – victorio

उत्तर

14

मैं अपने समाधान, से पहले movie.draw

canvas.scale((float)this.getWidth()/(float)movie.width(),(float)this.getHeight()/ (float)movie.height()); 

या

canvas.scale(1.9f, 1.21f);//this changes according to screen size 
+0

धन्यवाद, आपने वास्तव में मेरी मदद की! – offset