缩放后如何计算画布的新高度宽度?

时间:2012-07-19 10:05:33

标签: javascript html5

我正在研究HTML5项目,我遇到了somne​​问题。

实际上我有一个画布,我正在使用

绘制图像
ctx1.scale(0.5,0.5); // let assume
ctx1.drawImage(Image,0,0,canvas.width,canvas.height);

我想在缩放后计算图像的新高度(即scale = 0.5)。这样我就可以改变适合图像的画布高度和宽度(作为边界)。

先谢谢

1 个答案:

答案 0 :(得分:0)

这就像将宽度乘以比例尺一样简单!

虽然不确定语法:

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            //Database connection
            var connectionString = Configuration.GetConnectionString("DBConnectionStringName");

            //SOS Add Cors before MVC
            services.AddCors();


            //Register Repositories
            services.AddScoped<IRepository, Repository>();
            //The following line is added in order to have access on the HttpContext in controllers
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();



            services
                .AddMvc()
                .AddWebApiConventions()
                .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver = new DefaultContractResolver();
                    options.SerializerSettings.SerializationBinder = new DefaultSerializationBinder();

                });
            services.Configure<ApiBehaviorOptions>(options =>
            {
                options.SuppressConsumesConstraintForFormFileParameters = true;
                options.SuppressInferBindingSourcesForParameters = true;
                options.SuppressModelStateInvalidFilter = true;
            });

            services.AddKendo();
            services.AddTransient<IAuthorizationHandler, TokenHandler>();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("Token", policy =>
                    policy.Requirements.Add(new TokenRequirement()));
            });
            services.AddAuthentication(options =>
            {
                options.DefaultChallengeScheme = "DR";
                options.AddScheme<DKSchemeHandler>("DR", "DataVision");
            });

        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseStaticFiles();
            app.UseAuthentication();

            app.UseOwin();
            //SOS Add Cors before MVC
            app.UseCors(x => x
             .AllowAnyOrigin()
             .AllowAnyMethod()
             .AllowAnyHeader()
             .AllowCredentials());

            app.UseMvc();
        }
    }