Bitmap.FromFile(路径)和新的位图(路径)之间的区别 [英] Difference between Bitmap.FromFile(path) and new Bitmap(path)

查看:226
本文介绍了Bitmap.FromFile(路径)和新的位图(路径)之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 位图bitmap1 =新的位图(C:\\\ \\test.bmp); 
位图bitmap2 =(位图)Bitmap.FromFile(C:\\test.bmp);

一种方法比另一种更好吗?是否 Bitmap.FromFile(path)会将任何附加数据填充到位图图像中,还是仅仅代表新位图(路径)

在你的情况下,你要做的是调用FromFile方法并获取一个Image对象,然后将其转换为Bitmap。当你有Bitmap构造函数来做到这一点时为什么要这样做。
Bitmap.FromFile(路径)是否将任何附加数据填充到位图图像:


I woud like to know the difference between these two:

Bitmap bitmap1 = new Bitmap("C:\\test.bmp");
Bitmap bitmap2 = (Bitmap) Bitmap.FromFile("C:\\test.bmp");

Is one option better than the other one? Does Bitmap.FromFile(path) fills in any additional data to the bitmap image or is it just a delegate to new Bitmap(path)?

解决方案

'FromFile' method is available through base class 'Image'(which is an abstract class) to 'Bitmap' class and it returns an Image object. Where as 'Bitmap' is the child class which inherits 'Image' class and Bitmap constructor allows you to initialize Bitmap object directly.

In your case what you are trying to do is, call FromFile method and get an Image object then type cast it to Bitmap. Why to do this when you have Bitmap constructor to do this. Does Bitmap.FromFile(path) fills in any additional data to the bitmap image: No

这篇关于Bitmap.FromFile(路径)和新的位图(路径)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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