Summary C # Methods for BMP image display

Source: Internet
Author: User
Tags bmp image

The following code fragment uses the following code, so extract it and put it in front, so as not to repeat

MemoryStream ms = new MemoryStream (BMPIMGBUF); Bmpimgbuf BMP image buffer contains BMP headers and image data (images can come from files, networks, or devices, etc.)

1. Do not do the conversion, direct display

Bitmapframe BMF = bitmapframe.create (MS, Bitmapcreateoptions.none, Bitmapcacheoption.default);

This.imgViewer.Source = BMF; Imgviewer to Image control

2. Telescopic transform, then show

Mode 1).

var Imgdecoder = bitmapdecoder.create (MS, Bitmapcreateoptions.preservepixelformat, Bitmapcacheoption.none);
var img = imgdecoder.frames[0];

var target = new Transformedbitmap (IMG,
New ScaleTransform (
-640/img. Width * 96/img. Dpix,///If the width is less than the original image width, the width direction is reduced and conversely the magnification is negative, then the flip transform is superimposed
360/img. Height * 96/img. Dpiy,//ditto
0, 0));
This.imgViewer.Source = target;

Mode 2).

Transformedbitmap TBM = new Transformedbitmap ();
Tbm. BeginInit ();

Tbm. Source = Bitmapframe.create (MS, Bitmapcreateoptions.none, Bitmapcacheoption.default);

ScaleTransform st = new ScaleTransform ();
St.   ScaleX =-1; Mirrow image on vertical direction
Tbm. Transform = st;
Tbm. EndInit ();

This.imgViewer.Source = TBM;

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: 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.