首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

bitmap转换后,新的bitmap图像宽度变成了原来的2倍咋回事

2012-03-02 
bitmap转换后,新的bitmap图像宽度变成了原来的2倍怎么回事bitmap转换后,新的bitmap图像宽度变成了原来的2

bitmap转换后,新的bitmap图像宽度变成了原来的2倍怎么回事
bitmap转换后,新的bitmap图像宽度变成了原来的2倍怎么回事

函数如下。

输入一个bitmap,输出一个bitmap,把第二个bitmap Save到文件里,发现文件宽度像素没有变,但是内容被宽度拉伸了2倍,所以只显示了原来内容的左半部分,原来的右半部分溢出没有了,高度都是正好的,没有变,原内容的全部高度的内容都被显示出来了。

  Private Function get1bppBmp(ByVal dpiX As Integer, ByVal dpiY As Integer, ByVal tmpbm As System.Drawing.Bitmap) As System.Drawing.Bitmap
  Dim H As Integer
  Dim W As Integer

  Dim img As System.Drawing.Bitmap
  img = CType(tmpbm.Clone(), System.Drawing.Bitmap)

  W = img.Width
  H = img.Height

  Dim bd_img As System.Drawing.Imaging.BitmapData
  bd_img = img.LockBits(New System.Drawing.Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, img.PixelFormat)

  Dim baseBm As New System.Drawing.Bitmap(img.Width, img.Height, PixelFormat.Format1bppIndexed)

  baseBm.SetResolution(dpiX, dpiY)
  Dim bd_basebm As System.Drawing.Imaging.BitmapData
  bd_basebm = baseBm.LockBits(New System.Drawing.Rectangle(0, 0, baseBm.Width, baseBm.Height), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed)

  MsgBox("Basebm.with=")
  MsgBox(baseBm.Width)
  Dim X, Y, n As Int32
  Dim b As Byte
  For Y = 0 To H - 1
  n = bd_basebm.Stride * Y
  For X = 0 To W - 1
  If GetPixel4dpp1(X, Y, bd_img) Then

  b += CType(2 ^ (7 - X Mod 8), Byte)
  End If
  If (X + 1) Mod 8 = 0 Then

  System.Runtime.InteropServices.Marshal.WriteByte(bd_basebm.Scan0, n, b)
  n += 1
  b = 0
  End If
  Next
  If W Mod 8 > 0 Then

  System.Runtime.InteropServices.Marshal.WriteByte(bd_basebm.Scan0, n, b)
  b = 0
  End If
  Next

  img.UnlockBits(bd_img)
  baseBm.UnlockBits(bd_basebm)

  Return baseBm

  End Function


  Function GetPixel4dpp1(ByVal X As Int32, ByVal Y As Int32, ByVal Img2_Da As System.Drawing.Imaging.BitmapData) As Boolean
  Dim ofs As Int32 = Y * Img2_Da.Stride + X * 3
  Dim R, G, B As Byte
  R = System.Runtime.InteropServices.Marshal.ReadByte(Img2_Da.Scan0, ofs + 2)
  G = System.Runtime.InteropServices.Marshal.ReadByte(Img2_Da.Scan0, ofs + 1)
  B = System.Runtime.InteropServices.Marshal.ReadByte(Img2_Da.Scan0, ofs)

  Dim yy As Byte = CType(R * 0.3 + G * 0.59 + B * 0.11, Byte)
  If yy < 255 Then
  Return False
  Else
  Return True
  End If
  End Function


[解决办法]
我想知道
 img = CType(tmpbm.Clone(), System.Drawing.Bitmap)
中tmpbm是什么控件,然后显示模式是什么比如zoom,显示的图像大小多大.
[解决办法]
baseBm.SetResolution(dpiX, dpiY)
这里开始被缩放分辨率了.
[解决办法]

探讨

baseBm.SetResolution(dpiX, dpiY)
这里开始被缩放分辨率了.

热点排行