c# - .NET C# - 位图和图像加载的图像都小于预期

标签 c# .net image bitmap load

我正在尝试处理来自现代相机的典型 16 兆像素图像。选择一个随机图像,文件系统和我的图像编辑软件都说图像是 4608 x 3456。当我使用 new Bitmap(filename) 或 Image.FromFile(filename) 在 C# (VS2013 .Net 4.5) 中加载图像时,我成功加载了图像。但是,生成的图像大小为 1613 x 1210。现在,在某些情况下我想创建自定义大小的缩略图,这可以正常工作。但是,我还有另一个需要,我检测到“非正常”方向,我只想翻转/旋转显示,然后保存。

保存这些图像(不做任何调整,只需加载并保存)在磁盘上创建一个有效图像。但是,文件系统和我的图像工具都显示大小为 1613 x 1210。

如何加载全尺寸图像并将所有信息保存回磁盘?关于我做错了什么的任何想法?我只想在需要的地方旋转图像,我不想缩小它!

这是我尝试过的片段,正如下面评论中所 promise 的那样:

Bitmap bm = new Bitmap(fileName);
Image jpg = Image.FromFile(fileName);
jpg.Save("e:\\test.jpg");
bm.Save("e:\\test2.jpg");

这两个文件都小于它们的原始大小,并且与调试器显示的两个内存图像的宽度和高度相匹配。

根据建议的答案,我尝试了这段代码,但结果没有区别:

long width = 0;
long height = 0;

byte[] imageBytes = File.ReadAllBytes(fileName);
using (MemoryStream ms = new MemoryStream(imageBytes))
{
    Image jpg3 = Image.FromStream(ms);
    width = jpg3.Width;
    height = jpg3.Height;
    jpg3.Save("e:\\test3.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}

提前致谢。

[编辑] 后续帖子中的用户错误:

While it's true I do have a 4608x3456 size image of the very picture I am trying to load, I selected the wrong directory in my OpenFileDialog and was actually selected a, you guessed it, 1613 x 1210 version of this image. The code WAS loading the full thing, the silly operator (me) was gumming it up.

Before I post, I'll try the full-size image ... yeah, it works fine.

最佳答案

你能展示你的程序代码吗? 我下载了 5169x3423 大小的样本图像。 使用程序加载此图像,当我恢复它时,原始图像和新图像相同。

我将图像文件加载到字节数组并将其保存到位图。

private Image LoadImage()
{
    OpenFileDialog openFile = new OpenFileDialog();
    openFile.ShowDialog();
    byte[] byteImage = File.ReadAllBytes(openFile.FileName);

    Image myImage;
    using (var ms = new MemoryStream(byteImage))
    {
        myImage = Image.FromStream(ms);
    }
    return myImage;
 }


private void SaveImage(Image myImage)
{
    Bitmap bmp = new Bitmap(myImage);        
    // Temp save location
    bmp.Save("c:\\test\\myImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}

关于c# - .NET C# - 位图和图像加载的图像都小于预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26320637/

相关文章:

c# - 如何在 Serilog 中使用 ReadFrom.AppSettings

.net - 最容易学习和使用的 .NET ORM 框架?

ios - iPhone 4 英寸和 4.7 英寸屏幕的图像缩放

java - 旋转 bufferedImage 会改变图像的大小

c - Imagesc 等同于 C 语言?

c# - 在 C# 中动态访问类及其属性

c# - 类似于 WPF 的 Firebug 工具?

c# - 将方法作为传入方法的零个或多个参数作为参数传递?

c# - 有没有办法对多个值进行排序,并只保留每个值中最大的一个?

c# - .Net Core 控制台应用程序中的 Http 监听器?