如何在C#中动态更改图像的背景 [英] how to change background of an image dynamically in C#

查看:236
本文介绍了如何在C#中动态更改图像的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







我有一个精心设计的图像,名为MainImage。现在当我使用fileupload控件上传新图像时(图片将是护照照片尺寸复制类型),这里点击按钮我想让新图像(上传图像)在MainImage顶部略微透明(这里MainImage充当背景为上传的图片)并且应该存储在db。







我的表格如下所示


名称:TextBox



日期:TextBox



上传图片:fileuploadcontrol浏览



按钮





请让我我知道如何在c#中做到这一点。谢谢!

Hi ,


I have a well designed image which is named as MainImage. Now when I upload a new image using fileupload control(image will be passport photo size copy type) ,here on button click I want to make new image(uploaded image) slightly transparent on the top of MainImage (here MainImage acts as background for the uploaded image) and should be stored in db.



My form looks as below

Name : TextBox

Date : TextBox

Upload Image : fileuploadcontrol browse

Button


Please let me know how do I do it in c#. Thank you!

推荐答案

首先,你需要在你的aspx页面中放置一个Image元素(标签)。

First you need to place an Image element (tag) in your aspx page.
<asp:image id="Image1" runat="server" xmlns:asp="#unknown" />



成功上传图像文件后。您需要将此图像URL分配给该图像元素。


after you uploaded your image file successfully. You need to assign this image URL to that image element.

(imageElementID).ImageURL="../Upload/"+pc.Trim();





而且,在将文件保存到目录之前,您需要检查目录是否存在。所以它会是这样的。





And also, you need to check the directory whether its exists or not before save file into it. so it'll be something like.

if(!Directory.Exists(Server.MapPath(@"~/Upload")))
        Directory.CreateDirectory(Server.MapPath(@"~/Upload"));
    FileUpload1.PostedFile.SaveAs(Server.MapPath(@"~/Upload/" + pc.Trim()));





可以解决您的问题吗?



does that solve your problem?


这篇关于如何在C#中动态更改图像的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆