Home > Net >  How to save the image in the picturebox in JPG format
How to save the image in the picturebox in JPG format

Time:09-26

Now I can save as. BMP format, but how can save JPG format, what libraries to load?
Note is for JPG file format is not only a suffix

CodePudding user response:

 using System; 
Using System. Drawing;
Using System. Drawing. Imaging;
The class Example_SetJPEGQuality
{
Public static void Main ()
{
Bitmap myBitmap;
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;

//Create a Bitmap object -based on a BMP file.
MyBitmap=new Bitmap (" Shapes. BMP ");

//Get the an ImageCodecInfo object that represents the JPEG codec.
MyImageCodecInfo=GetEncoderInfo (" image/jpeg ");

//Create an Encoder object -based on the GUID

//for the Quality parameter category.
MyEncoder=Encoder. Quality;

//Create an EncoderParameters object.

//An EncoderParameters object has An array of EncoderParameter

//objects. In this case, there is only one

//EncoderParameter object in the array.
MyEncoderParameters=new EncoderParameters (1);

//Save the bitmap as a JPEG file with quality level 25.
MyEncoderParameter=new EncoderParameter (myEncoder, 25 l);
MyEncoderParameters. Param [0]=myEncoderParameter;
MyBitmap. Save (" Shapes025. JPG ", myImageCodecInfo, myEncoderParameters);

//Save the bitmap as a JPEG file with quality level 50.
MyEncoderParameter=new EncoderParameter (myEncoder, 50 l);
MyEncoderParameters. Param [0]=myEncoderParameter;
MyBitmap. Save (" Shapes050. JPG ", myImageCodecInfo, myEncoderParameters);

//Save the bitmap as a JPEG file with quality level 75.
MyEncoderParameter=new EncoderParameter (myEncoder, 75 l);
MyEncoderParameters. Param [0]=myEncoderParameter;
MyBitmap. Save (" Shapes075. JPG ", myImageCodecInfo, myEncoderParameters);
}
Private static ImageCodecInfo GetEncoderInfo (String mimeType)
{
Int j;
ImageCodecInfo [] encoders;
Encoders=ImageCodecInfo. GetImageEncoders ();
For (j=0; J & lt; Encoders. Length; + + j)
{
If (encoders [j] MimeType==MimeType)
Return encoders [j];
}
return null;
}
}

MSDN copy==I don't try, you can go to have a look at the image class

CodePudding user response:

 
Me. PictureBox1. Image. Save (" c: \ ABC. JPG ", System. Drawing. The Imaging. ImageFormat. Jpeg)

CodePudding user response:

There if the nuptial image function of storage to cover is how to solve?
Me. PictureBox1. Image. Save only cannot achieve the function of Save as cover

CodePudding user response:

 
If (File. Exist (x.j pg))
{
File. The Delete (x.j pg)
}
The else
{
//Save
}

CodePudding user response:

Using BMP as new bitmap (me) picturebox1) image. The width of the me. Picturebox1. Image. The height)
Using g=graphic. Fromimage (BMP)
G.d rawimage (me) picturebox1) image, 0, 0, BMP, width, BMP. Height)
End using
BMP. Save (decPath, imageformat. JPG)
End using
On the development machine, playing by heart, the code should be roughly,

CodePudding user response:

reference qq_15238669 reply: 3/f
there if the nuptial image function of storage to cover is how to solve?
Me. PictureBox1. Image. Save only cannot achieve the function of Save as cover

That's not the image. The save function of tube, to detect whether there is a name repetition, according to the savefiled... The filename to set the path of the save,

CodePudding user response:

# 2, it is not necessary to convert, bring their own functions
  • Related