本文介绍了用鼠标绘制加载的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这种方法,但是没有在图像上画图。只有当我试图在正确的边界(在图像之外)绘制它的工作。

  private var oldX:Number,oldY:Number; 
private var mode:String =modeBrush;
private function onMouseDown(e:MouseEvent):void {
oldX = e.localX;
ldY = e.localY;

private function onMouseMove(e:MouseEvent):void {
if(e.buttonDown){
var g:Graphics = currImg.graphics;
var mx:Number = e.localX;
var my:Number = e.localY;
g.lineStyle(10,0xFFFF00);
g.moveTo(oldX,oldY);
g.lineTo(mx,my);
}
oldX = mx;
oldY = my;
}
//图像我在加载运行时按钮点击

< s:Scroller left =2right =2top =2bottom =2>
< mx:Image id =currImgmouseMove =onMouseMove(event)mouseDown =onMouseDown(event)/>
< / s:Group>
< / s:Scroller>
< / s:BorderContainer>

更新
如果我这样做, !

  var line:UIComponent = new UIComponent(); 
line.graphics.lineStyle(2,0x990000,.75);
line.graphics.beginFill(0x000000);
line.graphics.moveTo(oldX,oldY);
line.graphics.lineTo(mx,my);
currImg.addChild(line);


解决方案

我知道你不能直接在图像上画线,您需要在UIComponent上绘制。



以下链接可能会帮助您:



I tried this way, but it doesn't draw on the image. Only if I tries to draw on right border (outside the image) it working.

private var oldX:Number, oldY:Number;
private var mode:String = "modeBrush";
   private function onMouseDown(e:MouseEvent):void {
    oldX = e.localX;
    ldY = e.localY;
   }
   private function onMouseMove(e:MouseEvent):void {
        if (e.buttonDown) {
       var g:Graphics = currImg.graphics;
       var mx:Number = e.localX;
       var my:Number = e.localY;
           g.lineStyle(10, 0xFFFF00);
       g.moveTo(oldX, oldY);
       g.lineTo(mx, my);
    }
        oldX = mx;
    oldY = my;
}
//image i'am loading at runtime by button click

 <s:BorderContainer id="everything" borderStyle="solid"  width="900" height="600">
      <s:Scroller left="2" right="2" top="2" bottom="2">
           <s:Group id="group">
         <mx:Image id="currImg" mouseMove="onMouseMove(event)" mouseDown="onMouseDown(event)"/>
           </s:Group>
       </s:Scroller>
     </s:BorderContainer>

UPDATEIf I do like this, everything works great!

var line:UIComponent = new UIComponent();
    line.graphics.lineStyle(2, 0x990000, .75);
    line.graphics.beginFill(0x000000);
    line.graphics.moveTo(oldX, oldY);
    line.graphics.lineTo(mx, my);
    currImg.addChild(line);
解决方案

As I know you cannot draw line directly on a image, you need to draw on a UIComponent.

The following link may help you:

http://groups.google.com/group/macromedia.flex.flex_builder/browse_thread/thread/bbcfc4e3e0a2e133http://www.axelscript.com/2008/06/11/drawing-in-flex-using-the-uicomponent/

这篇关于用鼠标绘制加载的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:21