转载图片浏览器-MFC+Flash

转载自:http://www.cnblogs.com/gameprogram/archive/2011/12/13/2285634.html

import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.ContextMenuEvent;
import flash.display.Loader;
import fl.motion.MatrixTransformer;
import flash.display.Sprite;
import flash.display.Shape;
import flash.system.LoaderContext;
import flash.display.DisplayObject;
import flash.geom.Transform;
import flash.geom.Point;
import flash.geom.Matrix;

/*

function fl_ClickToPosition(event:MouseEvent):void
{

    fscommand("MsgBox", "callC++");
}

function ChangeButton(msg:String):void
{
    btn.label = msg;
}
*/

fscommand("fullscreen","true")

var isEnd = false;
var showImg:Sprite;
var ldr :Loader;
var pic_width:Number;
var pic_height:Number;

var img:Bitmap;

// for drag move
var canDrag = false;
var LBDownX:Number;
var LBDownY:Number;

// for scale
var scaleW;
var scaleH;

// for rotate
var isRBDown = false;
var rotRadian = 0;
var rbX = 0;
var rbY = 0;
var rotScalar = 0.002;
var originX;
var originY;

// for change image
var go_limit = 0;
var go_left = false;
var go_right = false;
var size_scalarx = 1;
var size_scalary = 1;

//stage.stageWidth = 1300;

stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
//stage.addEventListener(MouseEvent.MOUSE_MOVE, onRBMove);

ExternalInterface.addCallback("MouseWheel",ZoomTo);
ExternalInterface.addCallback("RBDown",onRBDown);
ExternalInterface.addCallback("RBUp", onRBUp);
ExternalInterface.addCallback("RBMove",onRBMove);
ExternalInterface.addCallback("RotateX",onMoveRotateX);
ExternalInterface.addCallback("InitImage",LoadImage);
ExternalInterface.addCallback("ShowMouse",ShowMouse);

function ShowMouse():void
{
    Mouse.show();
}

var square:Shape = new Shape();
this.addChild(square);

function drawSqaure(x:Number, y:Number, w:Number, h:Number):void
{
    square.graphics.clear();
    square.graphics.lineStyle(2, 0);
    square.graphics.beginFill(200);
    //square.rotation = 20;
    square.graphics.drawRect(x, y, w, h);
    square.graphics.endFill();
}

stage.addEventListener(Event.RESIZE, DoResize);
function DoResize(evt:Event):void
{
    //fscommand("Resize",""+stage.stageHeight);
    go_limit = stage.stageWidth/10;

}

function Look_Left_Img(evt:Event):void
{
    trace("left click");
    fscommand("Look_Left_Img", "callC++");
}

function Look_Right_Img(evt:Event):void
{
    fscommand("Look_Right_Img", "callC++");
}

//function InitUI():void
//{
//    button_left.height = stage.stageHeight/5;
//    button_right.height = button_left.height;
//    button_left.width = stage.stageWidth/21;
//    button_left.x = button_left.width/2;
//    button_right.x = stage.stageWidth-button_right.width/2;
//    button_left.y = stage.stageHeight/2;
//    button_right.y = button_left.y;
//
//
//    button_left.addEventListener(MouseEvent.CLICK, Look_Left_Img);
//    button_right.addEventListener(MouseEvent.CLICK, Look_Right_Img);
//}

function InitCursor():void
{
    go_limit = stage.stageWidth/10;
    //fscommand("MsgBox",""+stage.stageWidth)
    left_cur.visible = false;
    right_cur.visible = false;
    normal_cur.visible = false;

    //left_cur.height = stage.stageHeight/10;
//    right_cur.height = left_cur.height;
//    left_cur.width = stage.stageWidth/15;
//    right_cur.width = left_cur.width;
//
//    normal_cur.height = stage.stageHeight/15;
//    normal_cur.width = stage.stageWidth/22;

//    fscommand("MsgBox",""+stage.scaleX);

//    normal_cur.scaleX = 1/stage.scaleX
    //normal_cur.scaleY = 1/stage.scaleY

    left_cur.scaleX = size_scalarx;
    left_cur.scaleY = size_scalary;
    normal_cur.scaleX = size_scalarx;
    normal_cur.scaleY = size_scalary;
    right_cur.scaleX = size_scalarx;
    right_cur.scaleY = size_scalary;
    trace("scaleX"+normal_cur.scaleX)

//    var cur_size = 16;
//    left_cur.height = cur_size;
//    left_cur.width = cur_size;
//    right_cur.height = cur_size;
//    right_cur.width = cur_size;
//    normal_cur.height = cur_size;
//    normal_cur.width = cur_size;

    trace(flash.system.Capabilities.screenResolutionX);

}

// load image
function LoadImage(filename:String, width:Number, height:Number):void
{

    //size_scalarx = stage.stageWidth/flash.system.Capabilities.screenResolutionX;
    //size_scalary = stage.stageHeight/flash.system.Capabilities.screenResolutionY;
    trace("size_scalar:"+size_scalarx)
    if (ldr == null)
    {
        ldr = new Loader();
    }
    else
    {
        ldr.unload();
    }

    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, ldr_complete);
    ldr.load(new URLRequest(filename), new LoaderContext());
    pic_width = width;
    pic_height = height;

    InitCursor();

    //InitUI();
}
LoadImage("E:/1.jpg", 460, 360);

function calculatePos(img):void
{
    trace(stage.stageWidth);
    trace(stage.stageHeight);
    var m_img_w = stage.stageWidth;
    var m_img_h = stage.stageHeight;
    var fix_w = m_img_w;
    var fix_h = m_img_h;

    if (pic_width > pic_height)
    {
        fix_w = m_img_w;
        fix_h = pic_height * m_img_w / pic_width;
    }
    else
    {
        fix_w = pic_width * m_img_h / pic_height;
        fix_h = m_img_h;
    }

    trace(fix_w);
    img.width = fix_w;
    img.height = fix_h;

    var wx = m_img_w - fix_w;
    var wy = m_img_h - fix_h;

    var m_img_x = 0;
    var m_img_y = 0;

    if (wx > 0)
        wx = wx/2;
    if (wy > 0)
        wy = wy/2;

    if( m_img_x > 0 )
        m_img_x = 0;

    if( m_img_x < wx )
        m_img_x = wx;

    if(m_img_y > 0)
        m_img_y = 0;

    if( m_img_y < wy )
        m_img_y = wy;    

    trace(m_img_x);
    showImg.x = m_img_x;
    showImg.y = m_img_y;
}

function reset_cursor():void
{
    trace("cur_X:"+stage.mouseX)
    if (stage.mouseX < go_limit)
    {
        //trace(evt.stageX);
        left_cur.visible = true;
        normal_cur.visible = false;

        go_left = true
    }
    else if ( stage.mouseX > stage.stageWidth - go_limit)
    {
        right_cur.visible = true;
        normal_cur.visible = false;

        go_right = true;
    }
    else
    {
        go_left = false;
        go_right = false;
        left_cur.visible = false;
        right_cur.visible = false;
        normal_cur.visible = true;
        normal_cur.x = stage.mouseX;
        normal_cur.y = stage.mouseY;
    }

    if (go_left)
    {
        left_cur.x = stage.mouseX;
        left_cur.y = stage.mouseY;
    }
    else if(go_right)
    {
        right_cur.x = stage.mouseX;
        right_cur.y = stage.mouseY;
    }
}

function ldr_complete(evt:Event):void
{
     var bmp:Bitmap = ldr.content as Bitmap;
    //trace(bmp);
     scaleW = 0.5 * bmp.width;
    scaleH = 0.5 * bmp.height;

    img = new Bitmap(bmp.bitmapData);
   // img.x = 0;
   // img.y = 0;
    img.rotation = 0;
    //img.width = 300;
    //img.height = 100;
    if (showImg != null)
        this.removeChild(showImg);
    showImg = new Sprite();

    //img.scaleX = size_scalarx;
    //img.scaleY = size_scalary;
    calculatePos(img);
    showImg.addChild(img);
    this.addChild(showImg);
    //showImg.rotationY =0;
    originX = 0;
    originY = 0;

    //showImg.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    showImg.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    showImg.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    showImg.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);

    //swapChildren(left_cur,showImg);
    setChildIndex(normal_cur, 3);
    setChildIndex(left_cur, 2);
    setChildIndex(right_cur, 1);
    setChildIndex(showImg, 0);
    //swapChildren(right_cur,showImg);

    reset_cursor();
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, onStageMouseMove)
stage.addEventListener(MouseEvent.CLICK, onStageMouseClick)
stage.addEventListener(MouseEvent.MOUSE_DOWN, onStageMouseDown)

function onStageMouseDown(evt:MouseEvent):void
{
    if (showImg.hitTestPoint(evt.stageX, evt.stageY))
    {
        trace("hit");
        canDrag = true;
        LBDownX = evt.stageX;
        LBDownY = evt.stageY;
    }
}

function onStageMouseMove(evt:MouseEvent):void
{
    Mouse.hide();
    if (evt.stageX < go_limit)
    {
        //trace(evt.stageX);
        left_cur.visible = true;
        normal_cur.visible = false;

        go_left = true
        left_cur.x = evt.stageX;
        left_cur.y = evt.stageY;
    }
    else if ( evt.stageX > stage.stageWidth - go_limit)
    {
        right_cur.visible = true;
        normal_cur.visible = false;

        go_right = true;
        right_cur.x = evt.stageX;
        right_cur.y = evt.stageY;
    }
    else
    {
        go_left = false;
        go_right = false;
        left_cur.visible = false;
        right_cur.visible = false;
        normal_cur.visible = true;
        normal_cur.x = evt.stageX;
        normal_cur.y = evt.stageY
    }

    if (canDrag)
    {
        //trace("move");
        var offsetX = evt.stageX - LBDownX;
        var offsetY = evt.stageY - LBDownY;

        LBDownX = evt.stageX;
        LBDownY = evt.stageY;

        showImg.x += offsetX;
        showImg.y += offsetY;
    }

}

function onStageMouseClick(evt:MouseEvent):void
{
    if (go_left)
    {
        trace("left");
        Mouse.hide();
        fscommand("Look_Left_Img", "callC++");
        //LoadImage("E:/mm.jpg", 850, 1000);
    }
    else if (go_right)
    {
        trace("right");

        fscommand("Look_Right_Img", "callC++");
        Mouse.hide();
    }
}

//function onMouseDown(evt:MouseEvent):void
//{
//    trace("mouse down");
//    canDrag = true;
//    LBDownX = evt.stageX;
//    LBDownY = evt.stageY;
//}

function onMouseMove(evt:MouseEvent):void
{

}

function onMouseUp(evt:MouseEvent):void
{
    canDrag = false;
}

function onMouseWheel(evt:MouseEvent):void
{
    trace(evt.delta);
    ZoomTo(evt.delta*0.2 , evt.delta*0.2);
}

function IsPosInImage(posX:Number, posY:Number):Boolean
{
    return img.hitTestPoint(posX,posY);

}

function ScaleAroundPoint(objToScale:DisplayObject,regX:Number, regY:Number, scaleX:Number, scaleY:Number):void
{
    if (!objToScale)
    {
        return;
    }

    var transformVector:Point = new Point((regX - objToScale.x)*scaleX, (regY - objToScale.y)*scaleY);

    objToScale.x = regX - transformVector.x;
    objToScale.y = regY - transformVector.y;
    objToScale.scaleX *= scaleX;
    objToScale.scaleY *= scaleY;
}

// scale
function ZoomTo(scalerH:Number, scalerW:Number):void
{
    if ((img.height + scaleH * scalerH) > 0 && (img.width + scaleW * scalerW) > 0)
    {

        if (IsPosInImage(stage.stageWidth/2, stage.stageHeight/2))
        {
            trace("hit");
            //imgMatrix.translate(-stage.width/2, -stage.height/2);
            //imgMatrix.tx -=stage.width/2;
            //imgMatrix.ty -=stage.height/2;
            //imgMatrix.scale(scalerW+1.0, scalerH + 1.0);

            //imgMatrix.tx +=stage.width/2;
            //imgMatrix.ty +=stage.height/2;

            //imgMatrix.translate(stage.width/2, stage.height/2);
            ScaleAroundPoint(showImg, stage.stageWidth/2, stage.stageHeight/2, scalerW+1.0, scalerH + 1.0);
        }
        else
        {
            //imgMatrix.translate(-(transformPoint.x + originX), -(transformPoint.y + originY));
//            imgMatrix.scale(scalerW+1.0, scalerH + 1.0);
//            imgMatrix.translate(transformPoint.x + originX, transformPoint.y + originY);
            ScaleAroundPoint(showImg, showImg.x+showImg.width/2, showImg.y+showImg.height/2, scalerW+1.0, scalerH + 1.0);
        }

        //showImg.scaleX += scalerW;
        //showImg.scaleY += scalerH;

        trace((showImg.x+showImg.width/2), (showImg.y+showImg.height/2));

        //showImg.transform.matrix = imgMatrix;

        //drawSqaure(showImg.x, showImg.y, showImg.width, showImg.height);
        //drawSqaure(img.x, img.y, img.width, img.height);
    }
}

// radian to degree
function RadianToDegree(radian:Number):Number
{
    return radian * 180/Math.PI;
}

// get radian after mouseMove
function RadianAfterMove(mouseX:Number, mouseY:Number):Number
{
    var flag:Boolean = true;

    //根据鼠标偏移距离来决定旋转角度大小
    var diffX:Number = mouseX - rbX;
    var diffY:Number = mouseY - rbY;

    var distance:Number = Math.sqrt(diffX*diffX+diffY*diffY);

    rbX = mouseX;
    rbY = mouseY;

    if (Math.abs(diffY) >= Math.abs(diffX))
    {
        if (diffY < 0)
            flag = false;
    }
    else
    {
        if (diffX < 0)
            flag = false;
    }

    if (flag)
    {
        rotRadian += distance * rotScalar;
        return distance * rotScalar;

    }
    else
    {
        rotRadian -= distance * rotScalar;
        return -distance * rotScalar;
    }

    //return rotRadian;
}

// right button down
function onRBDown(posX:Number, posY:Number):void
{
    isRBDown = true;
    rbX = posX;
    rbY = posY;
    //normal_cur.visible = false;
    //size_scalarx = stage.mouseX/rbX;
    //size_scalary = stage.mouseY/rbY;
}

// mouse move when right button down
//function onRBMove(evt:MouseEvent):void
function onRBMove(posX:Number, posY:Number):void
{
    if (isRBDown)
    {
        trace(showImg);
        normal_cur.x = normal_cur.x+ (posX - rbX)*size_scalarx;
        normal_cur.y = normal_cur.y + (posY - rbY)* size_scalary;
        //var imgMatrix:Matrix3D = showImg.transform.matrix3D;
//
//        var centerX:Number =  img.width / 2;
//
//        var centerY:Number =  img.height / 2;
//
//        var centerPoint:Vector3D = new Vector3D(centerX, centerY, 0);
//
//        var transformPoint:Vector3D = imgMatrix.transformVector(centerPoint);
//
//        imgMatrix.prependTranslation((transformPoint.x + originX), (transformPoint.y + originY), 0);
//
//        imgMatrix.prependRotation(RadianAfterMove(posX, posY)*10, Vector3D.Z_AXIS);
//
//        imgMatrix.prependTranslation(-transformPoint.x + originX, -transformPoint.y + originY, 0);
//
//        showImg.transform.matrix3D = imgMatrix;

        var imgMatrix:Matrix = showImg.transform.matrix;

        var centerX:Number = img.width/2;
        var centerY:Number = img.height/2;

        var centerPoint:Point = new Point(centerX, centerY);
        var transformPoint:Point = imgMatrix.transformPoint(centerPoint);

        imgMatrix.translate(-transformPoint.x, -transformPoint.y);
        imgMatrix.rotate(RadianAfterMove(posX, posY))
        imgMatrix.translate(transformPoint.x, transformPoint.y);

        showImg.transform.matrix = imgMatrix;
        //drawSqaure(showImg.x, showImg.y, showImg.width, showImg.height);
        //drawSqaure(img.x, img.y, img.width, img.height);
    }
}

// right button up
function onRBUp():void
{
    isRBDown = false;
    //normal_cur.visible = true;
    //normal_cur.x = stage.mouseX;
    //normal_cur.y = stage.mouseY;
}

function onMoveRotateX(posX:Number, posY:Number):void
{
    showImg.rotationX += RadianAfterMove(posX, posY)*10;
}

stop();

功能为左键拖动图片,中键缩放图片,右键旋转图片。

这是flash里的代码,生成SWF后,用MFC中的shockwaveflash读入,再截获右键消息,使右键菜单屏蔽。

时间: 2024-10-23 17:57:38

转载图片浏览器-MFC+Flash的相关文章

Android中轴旋转特效实现,制作别样的图片浏览器

转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/10766017 Android API Demos中有很多非常Nice的例子,这些例子的代码都写的很出色,如果大家把API Demos中的每个例子研究透了,那么恭喜你已经成为一个真正的Android高手了.这也算是给一些比较迷茫的Android开发者一个指出了一个提升自我能力的方向吧.API Demos中的例子众多,今天我们就来模仿其中一个3D变换的特效,来实现一种别样的图片浏览器

ViewPager做图片浏览器,加载大量图片OOM的问题修正

1 /** 2 * @author CHQ 3 * @version 1.0 4 * @date 创建时间: 2016/7/26 17:18 5 * @parameter 6 * @return 7 * 图片查看器 8 * //可以查看网络图片 9 * //可以查看本地图片 10 */ 11 public class PhotoScan extends Activity { 12 private PhotoViewPager mViewPager; 13 private List<View>

快速集成图片浏览器快速集成图片浏览器-&gt;MJPhotoBrowser的使用

介绍: 一个比较完整的图片浏览器,高仿了新浪微博的图片浏览效果,功能包括:下载浏览互联网图片,点击缩略图全屏显示图片.当加载较大图片时会出现圆形进度条,滑动浏览所有图片.保存图片到本地相册.GIF图片播放等.而且仅需几行代码就能添加图片浏览器功能. 项目地址:http://code4app.com/ios/快速集成图片浏览器/525e06116803fa7b0a000001 使用: for (int i = 0; i<3; i++) { UIImageView *img = [[UIImageV

IOS开发-图片浏览器实例-UIImageView的使用-懒加载-plist文件的使用

一.本文概述 一个使用UIImageView.UILabel.UIButton实现的图片浏览器的实例,界面如图:   功能描述: 1. 点击左右箭头切换图片.图片描述.图片序号: 2.第一张图片时左箭头不能点击 3.最后一张图片时右箭头不能点击 4.点击设置按钮出现一个可设置的界面(上图中黄色背景的部分)可以设置模式和对图片的缩放 实现概述: 1.搭建UI界面,使用UIImageView控件显示图片 2. 监听个按钮的点击 3. 切换图片内容,描述,序号.背景色及UIImageView的tran

简单图片浏览器

在设置开关灯的时候出了一点小问题,默认UISwitch为on当用if(sender.on)做判断时,第一次点击无效.后来调试默认为on,当改变状态时sender.on返回的是0,再次点击返回的是1.判断一个UISwitch为off可以用!sender.on 用到加载本地目录下的文件 //获取所有描述(通过解析plist文件来创建数组对象,比如传入文件的全路径) NSBundle *bundle = [NSBundle mainBundle]; //获取文件的全路径 NSString *path

CardLayout布局练习(小的图片浏览器)

1 /* 2 涉及Panel中的图片的加载,还有Frame的关闭的方法, CardLayout(int hgap, int vgap)就会决定卡片面板的大小 3 匿名类的使用... 4 */ 5 import java.awt.*; 6 import java.awt.event.*; 7 import javax.swing.*; 8 public class CardLayoutDemo extends Frame{ 9 Panel pCards=new Panel();//卡片面板 10

0821基本控件实例1 ——图片浏览器

一.项目需求--照片浏览器 二.开发步骤 1. 新建项目 2. 搭建UI界面 3. 建立IBOutlet,以便代码能够处理界面元素 4. 建立IBAction,以便界面上某些事件发生时执行方法 5. 代码实现 提示:为了便于理解,开发过程分两个步骤完成 三.演练说明 1.本节使用到的控件包括:UILabel,UIImageView,UISwitch,UIStepper和UISlider五个基本控件,除了第一个UILabel大家已经接触过之外,其他的四个控件都是第一次接触 2.开发过程中首先通过两

centos火狐浏览器安装flash player

无论是360还是百度的云盘,都没有linux的客户端,只能使用网页版,而使用网页版文件上传时提示需要安装flash player. 优酷看视频也需要安装flash player,总之,现在网络应用,很多是采用的flash player. 直接安装或火狐搜索插件安装均未能安装成功.只能自己下载安装. 安装文件我的网盘有备份:http://yunpan.cn/QNhzXVYAEjJAR (提取码:4b85) 下载后解压文件(tar -zxvf  *.tar.gz) 解压后有一个.so文件,还有一个u

IOS开发系列--无限循环的图片浏览器

--UIKit之UIScrollView 概述 UIKit框架中有大量的控件供开发者使用,在iOS开发中不仅可以直接使用这些控件还可以在这些控件的基础上进行扩展打造自己的控件.在这个系列中如果每个控件都介绍一遍确实没有必要,所谓授人以鱼不如授人以渔,这里会尽可能让大家明白其中的原理,找一些典型的控件进行说明,这样一来大家就可以触类旁通.今天我们主要来看一下UIScrollView的内容: UIView UIScrollView 实战--图片浏览器 UIView 在熟悉UIScrollView之前