将图像转换为字节流 [英] Converting image into stream of bytes

查看:90
本文介绍了将图像转换为字节流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在银色光4中将图像转换为字节流

推荐答案

您可以使用此简单的代码来了解如何转换流到byte [].

You can use this simple code to understand how convert stream to byte[].

public static byte[] ToByteArray(this WriteableBitmap bmp)
{
   // Init buffer
   int w = bmp.PixelWidth;
   int h = bmp.PixelHeight;
   int[] p = bmp.Pixels;
   int len = p.Length;
   byte[] result = new byte[4 * w * h];
   // Copy pixels to buffer
   for (int i = 0, j = 0; i < len; i++, j += 4)
  {
      int color = p[i];
      result[j + 0] = (byte)(color >> 24); // A
      result[j + 1] = (byte)(color >> 16); // R
      result[j + 2] = (byte)(color >> 8);  // G
      result[j + 3] = (byte)(color);       // B
   }
    return result;
}


这篇关于将图像转换为字节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆