带NTFS的Windows如何使用大量文件和目录?
在遇到性能问题或其他问题之前,是否有关于可以放在单个目录中的文件或目录限制的指导?
例如,在其中有一个包含100,000个文件夹的文件夹,这是一件好事吗?
我有一些二进制数据,我想保存为图像.当我尝试保存图像时,如果用于创建图像的内存流在保存之前关闭,则会引发异常.我这样做的原因是因为我正在动态创建图像,因此我需要使用内存流.
这是代码:
[TestMethod]
public void TestMethod1()
{
// Grab the binary data.
byte[] data = File.ReadAllBytes("Chick.jpg");
// Read in the data but do not close, before using the stream.
Stream originalBinaryDataStream = new MemoryStream(data);
Bitmap image = new Bitmap(originalBinaryDataStream);
image.Save(@"c:\test.jpg");
originalBinaryDataStream.Dispose();
// Now lets use a nice dispose, etc...
Bitmap2 image2;
using (Stream originalBinaryDataStream2 = new MemoryStream(data))
{
image2 = new Bitmap(originalBinaryDataStream2);
}
image2.Save(@"C:\temp\pewpew.jpg"); // This throws the GDI+ exception.
}
Run Code Online (Sandbox Code Playgroud)
有没有人对如何在关闭流的情况下保存图像有任何建议?我不能依赖开发人员记住在保存图像后关闭流.实际上,开发人员没有使用内存流生成映像的IDEA(因为它发生在其他地方的其他代码中).
我真的很困惑:(
我正在努力上传并将该图像的缩略图副本保存在缩略图文件夹中.
我正在使用以下链接:
http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx
但
newBMP.Save(directory + "tn_" + filename);
Run Code Online (Sandbox Code Playgroud)
导致异常"GDI +中发生了一般错误."
我试图给予文件夹权限,还试图在保存时使用新的单独的bmp对象.
编辑:
protected void ResizeAndSave(PropBannerImage objPropBannerImage)
{
// Create a bitmap of the content of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(fuImage.FileContent);
// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth / origHeight;
int thumbWidth = 100;
int thumbHeight = thumbWidth / sngRatio;
int bannerWidth = 100;
int bannerHeight = bannerWidth / sngRatio;
// Create a new …Run Code Online (Sandbox Code Playgroud) 我只是想知道C#中的随机数生成器是如何工作的.我也很好奇我如何制作一个从1-100 生成随机整数数字的程序.
有没有人有秘密配方来调整透明图像(主要是GIF)的大小而没有任何质量损失 - 这是怎么回事?
我尝试了很多东西,我得到的最接近的东西还不够好.
看看我的主要形象:
http://www.thewallcompany.dk/test/main.gif
然后缩放图像:
http://www.thewallcompany.dk/test/ScaledImage.gif
//Internal resize for indexed colored images
void IndexedRezise(int xSize, int ySize)
{
BitmapData sourceData;
BitmapData targetData;
AdjustSizes(ref xSize, ref ySize);
scaledBitmap = new Bitmap(xSize, ySize, bitmap.PixelFormat);
scaledBitmap.Palette = bitmap.Palette;
sourceData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
try
{
targetData = scaledBitmap.LockBits(new Rectangle(0, 0, xSize, ySize),
ImageLockMode.WriteOnly, scaledBitmap.PixelFormat);
try
{
xFactor = (Double)bitmap.Width / (Double)scaledBitmap.Width;
yFactor = (Double)bitmap.Height / (Double)scaledBitmap.Height;
sourceStride = sourceData.Stride;
sourceScan0 = sourceData.Scan0;
int targetStride = …Run Code Online (Sandbox Code Playgroud) 我有这个代码
private void saveImage()
{
Bitmap bmp1 = new Bitmap(pictureBox.Image);
bmp1.Save("c:\\t.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// Dispose of the image files.
bmp1.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
我已经在我的驱动器"c:\"上有一个图像t.jpg.
我希望每次程序运行时都用新图像替换它.但是GDI +错误显示
我怎么能解决它?
我经常搜索并尝试了很多,但我找不到合适的解决方案.
我想知道有没有办法确定指定字体的确切字形高度?
我的意思是在这里,当我想确定DOT字形的高度时,我应该获得较小的高度,但不能使用填充或字体大小来获得高度.
我已经找到了确定的解决方案准确字形宽度在这里(我用第二种方法),但它并不适用于高度工作.
更新:我需要.NET 1.1的解决方案
我有一些代码可以在几台机器上完美运行(开发,QA,UAT).不幸的是,在生产中我得到"GDI +中出现了一般错误" bmp.Save(ms, ImageFormat.Png);因此,我假设你无法重现问题,但也许有人可以发现我的错误.
一些注释,我已经搜索了很多常见的解决方案,请注意这是保存到一个MemoryStream所以大多数人建议不适用的文件权限问题,"bmp在打开时锁定"解决方案也是如此,因为我,'我在别的地方写作.最后,这不是因为png需要可搜索的流,因为它MemoryStream是可搜索的.
请注意,如果我将其更改为ImageFormat.Jpeg工作正常.我只对PNG有问题.我发现HKEY_CLASSES_ROOT\CLSID\{FAE3D380-FEA4-4623-8C75-C6B61110B681}由于权限,提到注册表项可能是问题所在.因此,我设置密钥以允许Everyone对此密钥具有读取访问权限,无需更改.
public static MemoryStream GenerateImage(string text)
{
MemoryStream ms = new MemoryStream();
using (Bitmap bmp = new Bitmap(400,400))
{
bmp.Save(ms, ImageFormat.Png);
ms.Position = 0;
}
return ms;
}
Run Code Online (Sandbox Code Playgroud)
这是完整的堆栈跟踪:
[ExternalException(0x80004005):GDI +中发生一般错误.]
System.Drawing.Image.Save(Stream stream,ImageCodecInfo encoder,EncoderParameters encoderParams)+616457
WP.Tools.Img.GenerateImage(String text)+383
注意:我的问题已经列举了拟议副本中的解决方案.没有问题.如果它们也会因JPEG而失败.
我有一个位图我想保存到磁盘,但我只是设法将其保存在与程序exe相同的目录中.
这是我让它工作的唯一方法:
image.save("img.jpg", ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
无论程序exe在哪里,我都希望将它保存在磁盘上的其他位置.这些都不起作用,我得到:GDI +中发生了一般性错误.
image.save("C:\\img.jpg", ImageFormat.Jpeg);
image.save(@"C:\\img.jpg", ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
编辑:顺便说一下,是否可以制作文件夹?这样的事情?(我总是得到同样的错误..)
image.save("foldername/img.jpg", ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
EDIT2:只有当文件夹已经存在时才能保存到文件夹中.可以有许可吗?什么需要进口?
我是c#的初学者.在我的项目中,如果我尝试使用以下代码来保存图像副本,则会出现错误"GDI +中发生一般错误"..我已经通过了这个链接,但我不知道他在说什么.
我尝试了下面的代码:
Bitmap bmpLarge = new Bitmap(ofdFlagsLarge.FileName);
bmpLarge.Save(@"\..\..\" + strLargePath); /* ERROR */
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我将图像从本地PC目录本身保存到同一台机器上的其他目录.