How do you rotate Bitmap by 90 degrees in Xamarin.Android? I am using ZXing.Net.Mobile, C#/.NET Barcode Scanning Library and would like to print barcode vertically. Thanks in advance.
Asked
Active
Viewed 881 times
2
-
check this: https://stackoverflow.com/questions/9015372/how-to-rotate-a-bitmap-90-degrees – Jaydeep Devda Jun 07 '17 at 11:17
-
I checked it. Unfortunately, there was no ZXing example provided. – mrisek Jun 20 '17 at 12:50
1 Answers
2
Once you have the barcode bitmap:
var barcodeWriter = new ZXing.Mobile.BarcodeWriter
{
Format = ZXing.BarcodeFormat.CODE_128,
Options = new ZXing.Common.EncodingOptions
{
Width = 300,
Height = 300
}
};
var barcode = barcodeWriter.Write("ZXing.Net.Mobile");
You can rotate it with this:
var barcodeRotated = RotateImage(barcode, 90);
Here's the function:
private Bitmap RotateImage(Bitmap src, float degrees)
{
var matrix = new Matrix();
matrix.PostRotate(degrees);
return Bitmap.CreateBitmap(src, 0, 0, src.Width, src.Height, matrix, true);
}
Result:
Hope this helps!

pinedax
- 9,246
- 2
- 23
- 30