private void LoadEnvMap() { if (mTutorial < 5) { return; } string texturePath = Path.GetFullPath(EnvMapPath); Bitmap image = new Bitmap(Image.FromFile(texturePath)); if (image == null) { return; } var imgData = image.LockBits(new System.DrawingCore.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat); BufferDesc bufferDesc = new BufferDesc() { Width = (uint)image.Width, Height = (uint)image.Height, Format = Format.UByte4, Type = BufferType.Input }; Buffer textureBuffer = new Buffer(OptixContext, bufferDesc); int stride = imgData.Stride; int numChannels = 4; unsafe { byte *src = (byte *)imgData.Scan0.ToPointer(); BufferStream stream = textureBuffer.Map(); for (int h = 0; h < image.Height; h++) { for (int w = 0; w < image.Width; w++) { UByte4 color = new UByte4(src[(image.Height - h - 1) * stride + w * numChannels + 2], src[(image.Height - h - 1) * stride + w * numChannels + 1], src[(image.Height - h - 1) * stride + w * numChannels + 0], 255); stream.Write <UByte4>(color); } } textureBuffer.Unmap(); } image.UnlockBits(imgData); TextureSampler texture = new TextureSampler(OptixContext, TextureSamplerDesc.GetDefault(WrapMode.Repeat)); texture.SetBuffer(textureBuffer); OptixContext["envmap"].Set(texture); }
private static byte[] ImageToByteArray(System.DrawingCore.Bitmap qrCodeImage) { byte[] byteArray = new byte[0]; using (MemoryStream memoryStream = new MemoryStream()) { qrCodeImage.Save(memoryStream, System.DrawingCore.Imaging.ImageFormat.Jpeg); byteArray = memoryStream.ToArray(); } return(byteArray); }
public IActionResult DecodeQR(DecodeQrViewModel viewModel) { System.DrawingCore.Bitmap bitmap = new System.DrawingCore.Bitmap(viewModel.FormFile.OpenReadStream()); try { BarcodeReader reader = new BarcodeReader { AutoRotate = true, TryInverted = true }; string qrcode = reader.Decode(bitmap).Text; return(new JsonResult(new { success = true, address = qrcode, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "GeneratedQRCodeSuccessfully") })); } catch (Exception ex) { return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "GeneratedQRCodeError") })); } }
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); string url = req.Query["url"]; ZXing.ZKWeb.BarcodeWriter barcodeWriter = new ZXing.ZKWeb.BarcodeWriter { Format = ZXing.BarcodeFormat.QR_CODE, Encoder = new QRCodeWriter(), Options = new EncodingOptions { Height = 150, Width = 150 }, Renderer = new ZXing.ZKWeb.Rendering.BitmapRenderer() }; System.DrawingCore.Bitmap qrCodeImage = barcodeWriter.Write(url); return(qrCodeImage != null ? (ActionResult) new FileContentResult(ImageToByteArray(qrCodeImage), "image/jpeg") : new BadRequestObjectResult("Please pass a name on the query string or in the request body")); }
/// <summary> /// uses the IBarcodeReaderGeneric implementation and the <see cref="ZXing.ZKWeb.BitmapLuminanceSource"/> class for decoding /// </summary> /// <param name="reader"></param> /// <param name="image"></param> /// <returns></returns> public static Result[] DecodeMultiple(this IBarcodeReaderGeneric reader, System.DrawingCore.Bitmap image) { var luminanceSource = new ZXing.ZKWeb.BitmapLuminanceSource(image); return(reader.DecodeMultiple(luminanceSource)); }