我成功地将单色位图打印到我的打印机,但是当打印项目时,图像右侧有一个大的黑色条纹.
这是原作

(扫描)打印机打印的内容

用于生成二进制blob的代码
Rectangle rect = new Rectangle(0, 0, Bitmap.Width, Bitmap.Height);
System.Drawing.Imaging.BitmapData bmpData = null;
byte[] bitVaues = null;
int stride = 0;
try
{
bmpData = Bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, Bitmap.PixelFormat);
IntPtr ptr = bmpData.Scan0;
stride = bmpData.Stride;
int bytes = bmpData.Stride * Bitmap.Height;
bitVaues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, bitVaues, 0, bytes);
}
finally
{
if (bmpData != null)
Bitmap.UnlockBits(bmpData);
}
string str = String.Format("GW{0},{1},{2},{3},", X, Y, stride, Bitmap.Height);
byte[] ascii = Encoding.ASCII.GetBytes(str);
byte[] …Run Code Online (Sandbox Code Playgroud) 我正在开发一个需要下载图像并在ImageView中显示它的Android应用程序.Bitmap传递给主java文件并添加到图像视图中,如下所示:
comic = (ImageView) findViewById(R.id.comic);
comic.setImageBitmap(c.getImageBitmap());
Run Code Online (Sandbox Code Playgroud)
这是有效的,除了图像的左侧从屏幕上消失.ImageView位于ScrollView中,可保持正确的大小.这意味着ScrollView右侧有黑色空间,图像向左侧切断.
ImageView的XML是这样的:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/comic"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:src="@drawable/xkcdlogo" />
</HorizontalScrollView>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
知道为什么我的图像会被切断吗?
谢谢!
如何将.NET位图和OpenCV图像指向同一块内存?我知道我可以从一个复制到另一个,但我更希望他们只指向相同的像素.
使用Emgu的解决方案的奖励积分.
调用TakePicture后,下面的代码作为jpeg图片回调执行.如果我将数据保存到磁盘,它是一个1280x960 jpeg.我试图改变图片大小,但这是不可能的,因为不支持更小的尺寸.JPEG是唯一可用的图片格式.
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream out = null;
Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length);
Bitmap sbm = Bitmap.createScaledBitmap(bm, 640, 480, false);
Run Code Online (Sandbox Code Playgroud)
data.Leng是预期的500k.执行BitmapFactory.decodeByteArray()后,bm的高度和宽度为-1,因此操作失败.
谢谢!
我有一个HBitmap,我从我用来转换PDF文档中的页面的API中收到.生成的位图是24位彩色位图.我试图确定,使用制作成pdfs的黑白扫描图像,在Foxit生成的位图上是黑白的.Foxit是PDF API.这是一些代码!(C/CLI)
// Get HBITMAP using Foxit's RenderPage function
// to convert to dib later
IntPtr hbitmap = FlattenPageToHBitmap(filename, page);
if (hbitmap == IntPtr::Zero)
return IntPtr::Zero;
Bitmap^ b = Bitmap::FromHbitmap(hbitmap);
bool isColor = false;
for (int y = 0; y < b->Height; y++)
{
for (int x = 0; x < b->Width; x++)
{
Color^ c = b->GetPixel(x, y);
unsigned int bits = (int)c->ToArgb();
bits = bits << 8;
bits = bits >> 8; //should get rid of A in …Run Code Online (Sandbox Code Playgroud) 我创建了以下函数,它将按要求执行(将HEX字符串转换为BitArray).我不确定函数的效率,但我现在的主要问题是Convert.ToInt64函数是特定于endian的.当将其移植到备用芯片组时,我们将得到不同的结果(或例外).所以有人能想到另一种方法来进行这种转换吗???
public BitArray convertHexToBitArray(string hexData)
{
string binary_values = "";
BitArray binary_array;
if (hexData.Length <= "FFFFFFFFFFFFFFFF".Length) // Max Int64
{
binary_values = Convert.ToString(Convert.ToInt64(hexData, 16), 2);
binary_array = new BitArray(binary_values.Length);
for (int i = 0; i < binary_array.Length; i++)
{
if (binary_values[i] == '0')
{
binary_array[i] = false;
}
else
{
binary_array[i] = true;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我删除了大部分错误/异常处理,以保持这个大小,所以请原谅.
我有一个要在页面中显示的图像,然后对图像应用一些视觉效果.例如斜角效果.一旦成功应用效果,有没有办法保存结果图像?
在C#中,我正在尝试使用最新的Mono在Mac OSX上加载png文件
using System.Drawing;
Bitmap bmp = new Bitmap("test.png");
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Either the image format is unknown or you don't have the required libraries to decode this format [GDI+ status: UnknownImageFormat]
Run Code Online (Sandbox Code Playgroud)
所有png文件都不会发生这种情况; 就是这个.

除非我切换到8bpp,否则在照相馆重新开始不会修复它.我需要安装什么来支持这个"特殊"的png文件吗?在窗户上工作正常.
我有一个代表
private delegate Color ColorDel(int x, int y);
Run Code Online (Sandbox Code Playgroud)
返回一个点的颜色,用于 Bitmap.GetPixel(x,y)
即使我之前直接将颜色放入位图中,作为a Color.Red,返回颜色与所有ARGB相同但不在名称上,而ffff0000不是Color.Red实际上的红色.
ToKnownColor也没有做到这一点.
有关此事的任何意见?
编辑,代码:
class ColorDelegateTest
{
private delegate Color ColorDel(int x, int y);
private static bool FoundColor(int x, int y, Color color, ColorDel dlgt)
{
var theColor = dlgt.Invoke(x, y);
//theColor = "{Name=ffff0000, ARGB=(255, 255, 0, 0)}"
//Color.Red = "{Name=Red, ARGB=(255, 255, 0, 0)}"
var r = dlgt.Invoke(x, y) == color; //False
var t = dlgt.Invoke(x, y) == Color.FromArgb(255, 255, 0, 0); …Run Code Online (Sandbox Code Playgroud) using (var bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb))
using (var g = Graphics.FromImage(bmp))
{
g.Clear(Color.Transparent);
g.DrawImage(image, 0, 0);
bmp.Save("image.bmp", ImageFormat.Bmp);
}
Run Code Online (Sandbox Code Playgroud)
问题应该是明确的:为什么保存到BMP 会将透明度变为黑色,而保存到PNG 会保留它?
只是为了澄清:图像采用Format8bppIndexed格式,其调色板确实包含透明色(例如,它正确地绘制在窗体/图片框上)
编辑:我的错,Bitmap.Save()实际上以Format32bppRgb格式保存BMP ,即使位图格式是Format32bppArgb.