保存已调整大小的位图时出错 [英] Error saving resized bitmap

查看:60
本文介绍了保存已调整大小的位图时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将

重新调整大小的图像保存回其原始位置时,我收到一般错误(不是很有帮助)。以下是代码片段:


Dim g As System.Drawing.Image =

System.Drawing.Image.FromFile(Me.File1.Value)

Dim thisFormat = g.RawFormat

Dim imgOutput As New Bitmap(g,800,600)

Dim strFileType As String


Dim strFileName As String = File1.PostedFile.FileName


''只有附加文件名而不是它的路径

Dim c As String = System.IO.Path.GetFileName(strFileName)

imgOutput.Save(strFileName)


最后一行似乎抛出错误。使用硬编码路径,我不会发现错误,所以我想我错过了一些东西。唯一的

差异是strFileName与硬编码的

路径相关的缺失(")。


任何想法?

谢谢你,我感谢你的帮助。

I get a generic error (not very helpful) when attempting to save a
re-sized image back to its original location. Here is the code snippet:

Dim g As System.Drawing.Image =
System.Drawing.Image.FromFile(Me.File1.Value)
Dim thisFormat = g.RawFormat
Dim imgOutput As New Bitmap(g, 800, 600)
Dim strFileType As String

Dim strFileName As String = File1.PostedFile.FileName

'' only the attched file name not its path
Dim c As String = System.IO.Path.GetFileName(strFileName)

imgOutput.Save(strFileName)

The last line seems to throw the error. With a hard coded path, I don''t
get an error so I think somehow I am missing something. The only
difference is the missing ("") around the strFileName vs. a hard coded
path.

Any ideas?
Thank you and I appreciate your help.

推荐答案

看起来你正在尝试从您的客户端上传文件然后

将其保存到服务器上的等效目录。我不认为你的意图是'b
。您需要将其保存到服务器上的映射路径

(具有写入权限的路径),然后将其下载到客户端上的原始

位置...我认为:-)


Gary

It looks like you are trying to upload a file from your client and then
save it to an equivalent directory on the server. I don''t think that''s
what you intended. You need to save it to a mapped path on the server
(one with write permissions) and then download it to the original
location on the client... I think :-)

Gary


好的。你说的是有道理的。但是如何将其下载到原始的

位置?


我想做的是获取新的位图并将其保存到SQL服务器

数据库。 (我已经可以听到十几个人告诉我这样做更容易了,但这是项目要求 - 我的双手并列)。


我可以从htmlinputfile控件保存到数据库,但是我很难将它调整到我创建的位图上。

应该发生什么是我拍了一张图片,如果它大于

a一定大小,请调整大小然后将其保存到数据库中。我可以

调整图像大小并将其保存到服务器。我可以拍摄一张图片,并将
上传到数据库。但我似乎无法拍摄图像,调整大小

然后将新版本保存到数据库中。


我很感激帮助!


目前,我正在尝试调整我的函数来从位图而不是输入控件中提取我需要的数据



然而,我觉得如果我能拍下照片就不会很酷,

调整它的大小,将新版本保存到
中的同一位置
文件输入控件然后将其上传到数据库''


听起来不错但不起作用。

Ok. What you say makes sense. But how do I download it to the original
location?

What I''d like to do is take the new bitmap and save it to a SQL Server
database. (I can already hear a dozen people telling me its easier NOT
to do that, but it''s the project requirement - my hands are tied).

I can save to a databse from the htmlinputfile control, but am
struggling with adapting it to the bitmap I''ve created.
What should be happening is that I take an image, if it is greater than
a certain size, resize it and then save it to the database. I can
resize the image and save it to the server. I can take an image and
upload it to a database. But I can''t seem to take the image, resize it
and then save the new version to the database.

I appreciate the help!

Currently, I''m trying to adapt my functions to pull the data I need
from the bitmap rather than the input control.
However, I thought ''wouldn''t it be cool, if I could take the image,
resize it, save the new version to the same location already in the
file input control and then upload it to the database''

Sounds good but not working.


我认为你的事情变得复杂了 - 只需将调整大小的文件写入

a映射的服务器路径,将其存储在SQL服务器中,然后删除

文件。不要担心覆盖发布的文件,AFAIK它不会在服务器上的任何地方生活,而不是在内存中(很高兴

更正)直到你实际保存它。显然客户端的原始图片

将保持不变,但我认为你不在乎

那个。


一切顺利,


加里

I think you''re complicating things - just write the resized file out to
a mapped server path, store it in your SQL server and then delete the
file. Don''t worry about overwriting the posted file, AFAIK it does not
live anywhere on the server other than in memory (happy to be
corrected) until you physically save it. Obviously the original image
on the client will be unchanged, but I assume you don''t care about
that.

All the best,

Gary


这篇关于保存已调整大小的位图时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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