Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# g代码1它只创建图像,但不指定图像标记。_C#_Gdi+_System.drawing - Fatal编程技术网

C# g代码1它只创建图像,但不指定图像标记。

C# g代码1它只创建图像,但不指定图像标记。,c#,gdi+,system.drawing,C#,Gdi+,System.drawing,我使用此解决方案 int G = 0; private void toolStripMenuItem17_Click(object sender, EventArgs e) { Directory.CreateDirectory("picture");// هذه العملية للرسم بدون ان يحذف بقية الرسومات G = G + 1; FormScreen(); memoryImage1.Save("picture\

我使用此解决方案

int G = 0;

private void toolStripMenuItem17_Click(object sender, EventArgs e)
{
  Directory.CreateDirectory("picture");// هذه العملية للرسم بدون ان يحذف بقية الرسومات
  G = G + 1;
  FormScreen();
  memoryImage1.Save("picture\\picture" + G.ToString() + ".jpg");
  pictureBox1.Image = Image.FromFile("picture\\picture" + G.ToString() + ".jpg");
}

下面的代码解决了我的问题

pictureBox1.Image=myImage;
  
Bitmap bmp = new Bitmap(pictureBox1.Image);
bmp.Save("C:\\Users/super/Desktop/robin.jpg");     

谢谢,用了这些我就成功了。我发布的代码再次工作。一个相关的问题,也许它会帮助别人-我得到了“一个通用错误发生在GDI+”打开位图已经。而且只在远程Web服务器上,不在本地测试机器上。事实证明,Azure IIS服务器上的GDI+无法处理GIMP生成的新格式BMP。我不得不a)用绘画重新保存BMP b)用未压缩的PNG代替c)用GIMP保存为24位BMP(质量更差)不确定我在修补的项目中做错了什么。。。但出于某种原因,MemoryStream/FileStream组合对我来说很有效(对于我的特定方法调用,有一些小的变化)。这是一篇5年前的文章的+1。@WernerCD我知道,问题(和修复)有点违反直觉-但这背后的过于简单的解释(在许多情况下,取决于具体情况)是您需要脱离原始位图对象(及其引用),内存流对此很有帮助。@NSGaga我当时正在使用MS(我将一个文件从PDF拉到位图/图像对象中)。。。但是,当我试图把位图/图像对象拉出来并放到磁盘上时,它本身就出问题了。
Memory/FileStream
vs
bitmap.Save(…)
是我认为对我起作用的反直觉的步骤。我想。毫无疑问,这给了我在几个小时的问题讨论后所寻求的动力。当然,我就是这样,我把它投了赞成票,这样其他人就不应该再浪费时间了。还要确保你的路径也包含文件名。错误不能只报告这样一个基本的问题,这是多么愚蠢啊!简单的答案是最好的!这也是一个很好的建议。你可以编辑你的帖子,而不是删除并重新发布一篇新的帖子。这是一个很好的答案,可惜它被许多与坏路径相关的重复答案所掩盖。无法销毁基础流。另一种方法是从旧位图创建一个新位图:新建位图(旧位图)。保存(…)这是一种可怕的做法,您永远不应该授予全局完全控制权!
    Bitmap newBitmap = new Bitmap(thumbBMP);
    thumbBMP.Dispose();
    thumbBMP = null;
    newBitmap.Save("~/image/thumbs/" + "t" + objPropBannerImage.ImageId, ImageFormat.Jpeg);
string outputFileName = "...";
using (MemoryStream memory = new MemoryStream())
{
    using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
    {
        thumbBMP.Save(memory, ImageFormat.Jpeg);
        byte[] bytes = memory.ToArray();
        fs.Write(bytes, 0, bytes.Length);
    }
}
    // Once finished with the bitmap objects, we deallocate them.
    originalBMP.Dispose();

    bannerBMP.Dispose();
    oGraphics.Dispose();
using (var newBitmap = new Bitmap(thumbBMP)) {
    newBitmap.Save("~/image/thumbs/" + "t" + objPropBannerImage.ImageId, ImageFormat.Jpeg);
}
System.Drawing.Image imageToBeResized = System.Drawing.Image.FromStream(fuImage.PostedFile.InputStream);
        int imageHeight = imageToBeResized.Height;
        int imageWidth = imageToBeResized.Width;
        int maxHeight = 240;
        int maxWidth = 320;
        imageHeight = (imageHeight * maxWidth) / imageWidth;
        imageWidth = maxWidth;

        if (imageHeight > maxHeight)
        {
            imageWidth = (imageWidth * maxHeight) / imageHeight;
            imageHeight = maxHeight;
        }

        Bitmap bitmap = new Bitmap(imageToBeResized, imageWidth, imageHeight);
        System.IO.MemoryStream stream = new MemoryStream();
        bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
        stream.Position = 0;
        byte[] image = new byte[stream.Length + 1];
        stream.Read(image, 0, image.Length);
        System.IO.FileStream fs
= new System.IO.FileStream(Server.MapPath("~/image/a.jpg"), System.IO.FileMode.Create
, System.IO.FileAccess.ReadWrite);
            fs.Write(image, 0, image.Length);
img1.Save(Server.MapPath("/Upload/test.png", System.Drawing.Imaging.ImageFormat.Png);


--Above code need one change, as you need to put close brackets on Server.MapPath() method after writing its param.
img1.Save(Server.MapPath("/Upload/test.png"), System.Drawing.Imaging.ImageFormat.Png);
    I used below logic while saving a .png format. This is to ensure the file is already existing or not.. if exist then saving it by adding 1 in the filename

Bitmap btImage = new Bitmap("D:\\Oldfoldername\\filename.png");
    string path="D:\\Newfoldername\\filename.png";
            int Count=0;
                if (System.IO.File.Exists(path))
                {
                    do
                    {
                        path = "D:\\Newfoldername\\filename"+"_"+ ++Count + ".png";                    
                    } while (System.IO.File.Exists(path));
                }

                btImage.Save(path, System.Drawing.Imaging.ImageFormat.Png);
int count = Directory.EnumerateFiles(System.Web.HttpContext.Current.Server.MapPath("~/images/savedimages"), "*").Count();

var img = Base64ToImage(imgRaw);

string path = "images/savedimages/upImages" + (count + 1) + ".png";

img.Save(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(path)));

return path;
String path = "images/savedimages....
String path = "/images/savedimages....
private Bitmap getImage(byte[] imageBinaryData){
    .
    .
    .
    Bitmap image;
    using (var stream = new MemoryStream(imageBinaryData))
    {
        image = new Bitmap(stream);
    }
    return image;
}
image.Save(path);
private Bitmap getImage(byte[] imageBinaryData){
   .
   .
   .
   Bitmap image;
   var stream = new MemoryStream(imageBinaryData))
   image = new Bitmap(stream);

   return image;
}
using (var image = getImage(binData))
{
   image.Save(path);
}
using (Bitmap bmp = new Bitmap(webStream))
{
     using (Bitmap newImage = new Bitmap(bmp))
     {
         newImage.Save("c:\temp\test.jpg", ImageFormat.Jpeg);
     }
}
using (Bitmap bmp = new Bitmap(webStream))
{

     using (Bitmap newImage = new Bitmap(bmp))
     {
        newImage.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution);
        Rectangle lockedRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
        BitmapData bmpData = newImage.LockBits(lockedRect, ImageLockMode.ReadWrite, bmp.PixelFormat);
        bmpData.PixelFormat = bmp.PixelFormat;
        newImage.UnlockBits(bmpData);
        using (Graphics gr = Graphics.FromImage(newImage))
         {
             gr.SmoothingMode = SmoothingMode.HighQuality;
             gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
             gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
         }

         foreach (var item in bmp.PropertyItems)
         {
             newImage.SetPropertyItem(item);
         }
         newImage.Save("c:\temp\test.jpg", ImageFormat.Jpeg);
    }
}
int G = 0;

private void toolStripMenuItem17_Click(object sender, EventArgs e)
{
  Directory.CreateDirectory("picture");// هذه العملية للرسم بدون ان يحذف بقية الرسومات
  G = G + 1;
  FormScreen();
  memoryImage1.Save("picture\\picture" + G.ToString() + ".jpg");
  pictureBox1.Image = Image.FromFile("picture\\picture" + G.ToString() + ".jpg");
}
pictureBox1.Image=myImage;
  
Bitmap bmp = new Bitmap(pictureBox1.Image);
bmp.Save("C:\\Users/super/Desktop/robin.jpg");