public
static
byte
[] BitmapToBytes(Bitmap Bitmap)
{
try
{
using (MemoryStream ms =
new
MemoryStream())
{
Bitmap.Save(ms, Bitmap.RawFormat);
byte
[] byteImage =
new
Byte[ms.Length];
byteImage = ms.ToArray();
return
byteImage;
}
}
finally
{
}
}
BitmapToBytes(img).Reverse().Take(2);
//然后判断是不是217,255
|
Open the file as a binary file. Read the last 2 bytes to determine.
Or read all, starting at the end of the search ffd9, found that is OK.
Sometimes using the camera network server to transmit pictures, suddenly broken nets, resulting in incomplete images, are the upper half of the picture, the board part, can not be previewed. How to determine if a picture (JPG) is complete in C #
The bitmap class in C # implements some methods for image manipulation by importing the following two packages: System.Drawing; System.Drawing.Imaging;Production object:Bitmap BM = new Bitmap ("C:/1.bmp"); Scaling: Bitmap bm1 = new Bitmap (bm,width,height); Format conversion: Bm.save ("C:/1.jpg", imagefromat.jpeg); bm1. Save ("C:/1.gif", imageformat.gif); Cut an area://Cut size int cutwidth;int cutheight; Graphics g;//creates a bitmap pair like Bitmap bm1 = new Bitmap (WIDTH,HEIGHT,PIXELFORMAT.FORMAT32BPPRGB) with a size of cut size and a pixel format of 32-bit RGB;// Define an area Rectangle RG = new Rectangle (0,0,cutwidth,cutheight);//bitmap to be drawn to G = Graphics.fromimage (BM1);// Draws the area specified in the BM inside RG to bm1g. DrawImage (BM,RG) ============================================c#bitmap replaces a part of another bitmap
Bitmap BM = new Bitmap (width, height);//Create a new Bitmap bitmap
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage (BM); Create a canvas based on the new Bitmap bitmap
G.clear (System.Drawing.Color.Black);//use Black to reset the canvas
G.drawimage (source bitmap, ...); Draw "Source Bitmap", followed by a number of parameters to control the size, coordinates and other functions. ==================================================
C # Image processing: Rotate the image at any angle // <summary>
/// rotate at any angle
</summary>
/// <param name= "BMP" > Original figure bitmap</param>
/// <param name= "angle" > Swivel angle </param>
/// <param name= "Bkcolor" > Background color </param>
/// <returns> output bitmap</returns>
Public static Bitmap kirotate (Bitmap bmp, float angle, Color bkcolor)
...{
int w = BMP. Width + 2;
int h = BMP. Height + 2;
PixelFormat PF;
if (Bkcolor = = color.transparent)
...{
PF = Pixelformat.format32bppargb;
}
Else
...{
PF = bmp. PixelFormat;
}
Bitmap tmp = new Bitmap (W, H, pf);
Graphics g = graphics.fromimage (TMP);
G.clear (Bkcolor);
G.drawimageunscaled (BMP, 1, 1);
G.dispose ();
GraphicsPath Path = new GraphicsPath ();
Path. AddRectangle (New RectangleF (0f, 0f, W, h));
Matrix Mtrx = new Matrix ();
Mtrx. Rotate (angle);
RectangleF RCT = path. GetBounds (MTRX);
Bitmap DST = new Bitmap ((int) RCT. Width, (int) RCT. Height, PF);
g = Graphics.fromimage (DST);
G.clear (Bkcolor);
G.translatetransform (-RCT. X,-RCT. Y);
G.rotatetransform (angle);
G.interpolationmode = interpolationmode.highqualitybilinear;
g.drawimageunscaled (TMP, 0, 0);
G.dispose ();
Tmp. Dispose ();
Return DST;
}
The bitmap class in C # detects image integrity by manipulating images