The bitmap class in C # detects image integrity by manipulating images

Source: Internet
Author: User

publicstaticbyte[] BitmapToBytes(Bitmap Bitmap)        {            try            {                using (MemoryStream ms = newMemoryStream())                {                    Bitmap.Save(ms, Bitmap.RawFormat);                    byte[] byteImage = newByte[ms.Length];                    byteImage = ms.ToArray();                    returnbyteImage;                }            }            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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.