标签: pixelformat

Android TextView setTextSize错误地增加了文本大小

这是TextView的扩展.getTextSize()setTextSize()没有被覆盖,我没有扩展这些方法.编程1.6,API级别4.

此代码中的循环导致每次迭代时大小乘以1.5,例如,如果大小最初从200读取getTextSize,则setTextSize(size)调用,getTextSize再次调用则读回300.

public void shrinkTest() {
    float size = this.getTextSize(); 
    while (size > 8) {
        this.setTextSize(size);
        size = this.getTextSize();
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么是这样?

android pixels textview pixelformat

46
推荐指数
3
解决办法
3万
查看次数

对PixelFormat感到困惑

我对Android上的PixelFormat感到困惑.

我的设备是摩托罗拉Defy.

我有两个问题:

  • 在Android 2.3上getWindowManager().getDefaultDisplay().getPixelFormat()返回4代表RGB_565.据我所知,我的设备有16M颜色,这意味着每个像素3个(或4个alpha通道)字节:
                2^(8*3) = 2^24 = 16M
Run Code Online (Sandbox Code Playgroud)

RGB_565格式每像素有2个字节(16位),代表65K颜色:

                2^(8*2) = 2^16 = 65K
Run Code Online (Sandbox Code Playgroud)

那么,为什么getPixelFormat()不返回每像素3(或4个像RGBA)字节的格式?它是否显示驱动程序问题?我可以设置PixelFormatRGBA_8888(或模拟)吗?

  • 在Android 4.1(自定义ROM)上,getPixelFormat()返回5.但是这个价值没有记载.它代表什么?实际上,在这种情况下效果与常数相同4.但是从这次讨论中我发现5代表RGBA_8888(但没有证据证明该陈述).那么如何才能找出设备屏幕的真实格式?另外我在Android 2.2上发现了一个中文设备,也有PixelFormat 5个,但真正的格式是4(就像我的摩托罗拉).

我搜索了这些问题但没有发现任何问题.我发现唯一的东西是nexus 7也有5种格式.

更新:

我找到了方法,getWindow().setFormat()但它实际上并没有改变主像素格式.

android pixelformat

14
推荐指数
1
解决办法
1万
查看次数

OpenGL纹理上传:UNSIGNED_BYTE vs UNSIGNED_INT_8_8_8_8

我正在调用glTexSubImage2D.如果我的像素格式是GL_RGBA,那么像素类型GL_UNSIGNED_BYTEGL_UNSIGNED_INT_8_8_8_8完全相同吗?

另外,这两对是否相同?

  • Format = GL_RGBA, Type = GL_UNSIGNED_INT_8_8_8_8
  • Format = GL_BGRA, Type = GL_UNSIGNED_INT_8_8_8_8_REV

我已经尝试过阅读OpenGL规范和GL_EXT_packed_pixels规范,但说实话,我无法做出它们的头或尾.

opengl pixelformat

10
推荐指数
1
解决办法
6301
查看次数

如何获得BitmapSource的PixelFormat

我使用以下内容将a转换BitmapSourceBitmap:

internal static Bitmap ConvertBitmapSourceToBitmap(BitmapSource bitmapSrc)
{
    int width = bitmapSrc.PixelWidth;
    int height = bitmapSrc.PixelHeight;
    int stride = width * ((bitmapSrc.Format.BitsPerPixel + 7) / 8);

    byte[] bits = new byte[height * stride];

    bitmapSrc.CopyPixels(bits, stride, 0);

    unsafe
    {
        fixed (byte* pBits = bits)
        {
            IntPtr ptr = new IntPtr(pBits);

            return new System.Drawing.Bitmap(
                width,
                height,
                stride,
                System.Drawing.Imaging.PixelFormat.Format32bppPArgb, //The problem
                ptr);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何得到PixelFormatBitmapSource,所以我的图像被破坏了.

对于上下文,我使用这种技术,因为我想加载一个tiff,可能是8或16灰色或24或32位颜色,我需要PixelFormat保留.我更喜欢修复ConvertBitmapSourceToBitmap它,因为它相当方便,但也很乐意用更好的技术替换以下代码,从BitmapSource创建一个Bitmap:

Byte[] buffer = File.ReadAllBytes(filename.FullName);
using …
Run Code Online (Sandbox Code Playgroud)

c# bitmapsource pixelformat

7
推荐指数
1
解决办法
4116
查看次数

C#Bitmap对象,颜色显示为透明

我正在使用C#中的程序来截取用户屏幕的一部分.尽管它应该是最有效的,但我最近遇到了一个问题.似乎(至少)一个像素颜色在输出图像中始终显示为透明.颜色#0D0B0C(RGB 13,11,12)的任何实例在保存的png中显示为透明.这是将PixelFormat设置为Format32bppArgb.如果我将其设置为Format32bppRgb或Format24bppRgb,则相同的像素颜色在保存的png中显示为黑色.

我不知道是什么导致这种情况,但我唯一能做的就是"修复"它是在执行CopyFromScreen()之前将图形对象清除为该颜色.出于某些原因,我不愿意这样做.首先,我不知道这是唯一有问题的颜色(使用16,777,216种颜色有很多可能性),其次,我讨厌修复黑客,这似乎是一个黑客修复.

任何人都可以解释可能导致这个问题的原因吗?我在位图创建上搞乱了PixelFormat,在CopyFromScreen方法中使用了CopyPixelOperation,似乎没什么用.将图形对象清除为该颜色"修复"的事实似乎告诉我透明度来自屏幕数据本身,但这没有意义.我一直盯着这个问题太久了,我想我需要对它有一个全新的看法.如果有人知道为什么会发生这种情况,我很乐意听到.谢谢.

c# graphics image bitmap pixelformat

6
推荐指数
1
解决办法
1112
查看次数

ffmpeg:指定/强制输入 H.264 视频的像素格式

我有一些 MP4 视频文件的标题信息中缺少像素格式。我已经尝试设置probesizeanalyzeduration为它们的最大值2147483647,但没有帮助。

所以我知道这些视频可能已损坏,但如果这是唯一丢失的信息,我想我可以通过重建它们的标题信息或通过强制像素格式以某种方式解码它们来恢复它们。有没有人知道这是否可能?关于文件的更多背景:

媒体信息:

$ mediainfo DJI_0090.MOV 
General
Complete name                            : DJI_0090.MOV
Format                                   : MPEG-4
Format profile                           : QuickTime
Codec ID                                 : qt   2014.02 (qt  )
File size                                : 165 MiB
Duration                                 : 22 s 322 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 61.8 Mb/s
Encoded date                             : UTC 2017-05-31 18:04:45
Tagged date                              : UTC 2017-05-31 18:04:45
Comment                                  : 0.9.145
©gpt                                     : -170.60
©gyw                                     : +157.30
©grl                                     : +0.00
IsTruncated                              : …
Run Code Online (Sandbox Code Playgroud)

mp4 ffmpeg pixelformat

6
推荐指数
0
解决办法
6384
查看次数

如何在RenderTargetBitmap中使用PixelFormats.IndexedX?

我期待呈现DrawingVisual(在示例性视觉)到使用位图RenderTargetBitmap的观点来设置此位图作为背景的Canvas,如下:

var bmp = new RenderTargetBitmap(2000, 50, 120, 96, PixelFormats.Indexed2);
bmp.Render(visual);
var brush = new ImageBrush(bmp) { Stretch = Stretch.Fill };
Canvas.Background = brush;
Run Code Online (Sandbox Code Playgroud)

当使用PixelFormats.Default最后一个参数时RenderTargetBitmap,图像按预期呈现.然而,当我选择PixelFormats.Indexed2(或任何的PixelFormats.IndexedX),我的代码似乎退出方法没有例外,该bmp.Render线不会被调用,因此在图像上没有显示Canvas.

如何使用IndexedX像素格式RenderTargetBitmap?或者还有其他方法可以减少图像的内存占用量吗?它只使用三种颜色,所以使用调色板而不是32位RGB似乎是要走的路.

wpf pixelformat rendertargetbitmap

5
推荐指数
1
解决办法
3073
查看次数

创建新的Texture2D时如何选择像素格式?

我正在使用SharpDX Toolkit,我正在尝试以编程方式创建Texture2D,因此我可以手动指定所有像素值.我不确定用它创建什么像素格式.

SharpDX甚至没有记录工具包的PixelFormat类型(他们有另一个PixelFormat类的文档,但它适用于WIC,而不是工具包).我确实找到了它包装的DirectX枚举,DXGI_FORMAT,但它的文档没有给我如何选择格式的任何有用的指导.

我习惯于使用每个颜色通道8位加8位alpha的旧32位位图格式,这对我来说已经足够了.所以我猜最简单的选择是R8G8B8A8或B8G8R8A8.我选择哪个重要?它们都将在所有硬件上得到完全支持吗?

甚至一旦我选择了其中之一,我就需要进一步指定它是SInt,SNorm,Typeless,UInt,UNorm还是UNormSRgb.我不需要sRGB色彩空间.我不明白Typeless应该是什么.UInt似乎是最简单的 - 只是一个普通的无符号字节 - 但事实证明它不起作用; 我没有收到错误,但我的纹理不会在屏幕上绘制任何内容.UNorm有效,但文档中没有任何内容可以解释为什么UInt没有.所以现在我很偏执,因为它可能无法在其他视频卡上运行.

这是我得到的代码,如果有人想看到的话.下载SharpDX完整包,打开SharpDXToolkitSamples项目,转到SpriteBatchAndFont.WinRTXaml项目,打开SpriteBatchAndFontGame类,并在指示的位置添加代码:

// Add new field to the class:
private Texture2D _newTexture;

// Add at the end of the LoadContent method:
_newTexture = Texture2D.New(GraphicsDevice, 8, 8, PixelFormat.R8G8B8A8.UNorm);
var colorData = new Color[_newTexture.Width*_newTexture.Height];
_newTexture.GetData(colorData);
for (var i = 0; i < colorData.Length; ++i)
    colorData[i] = (i%3 == 0) ? Color.Red : Color.Transparent;
_newTexture.SetData(colorData);

// Add inside the Draw method, just before the call to spriteBatch.End():
spriteBatch.Draw(_newTexture, new Vector2(0, …
Run Code Online (Sandbox Code Playgroud)

directx pixelformat sharpdx

5
推荐指数
1
解决办法
4644
查看次数

Linux 帧缓冲区像素位域通用实现

我正在编写一个小型库来与 Linux 的帧缓冲区抽象接口。我的所有显卡都使用相同的像素格式(每个通道一个八位字节,四个通道,BGRA 排序),因此到目前为止,库仅采用这种格式。但是,如果我希望该库在任何 Linux 帧缓冲区上工作,帧缓冲区 API 提供了我必须使用的像素格式数据。你不需要知道帧缓冲区是如何工作的来回答这个问题(我希望),只需要一些我不熟悉的小技巧。这是我的标题中提供的像素格式信息:

/* Interpretation of offset for color fields: All offsets are from the right,
 * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
 * can use the offset as right argument to <<). A pixel afterwards is a bit
 * stream and is written to video memory as that unmodified.
 *
 * For pseudocolor: offset and length should be the same for all color
 * components. Offset specifies the position …
Run Code Online (Sandbox Code Playgroud)

c linux bit-manipulation framebuffer pixelformat

5
推荐指数
1
解决办法
1043
查看次数

图像读取器内将帧从 YUV_420_888 格式错误转换为 NV21

我配置了代码,以便使用对象和其余众所周知的APIYUV_420_888从设备的摄像头获取帧流。现在我需要将这些帧转换为像素格式并调用本机函数,该函数期望这种格式的帧执行某些计算。这是我在图像读取器回调中使用的代码,用于重新排列帧的字节:imageReadercamera2NV21

        ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader mReader) {
                Image image = null;
                image = mReader.acquireLatestImage();
                if (image == null) {
                    return;
                }                           

                byte[] bytes = convertYUV420ToNV21(image);

                nativeVideoFrame(bytes);
                image.close();   
            }
        };

private byte[] convertYUV420ToNV21(Image imgYUV420) {

    byte[] rez;

    ByteBuffer buffer0 = imgYUV420.getPlanes()[0].getBuffer();
    ByteBuffer buffer1 = imgYUV420.getPlanes()[1].getBuffer();
    ByteBuffer buffer2 = imgYUV420.getPlanes()[2].getBuffer();

    int buffer0_size = buffer0.remaining();
    int buffer1_size = buffer1.remaining();
    int buffer2_size = buffer2.remaining();

    byte[] buffer0_byte = new byte[buffer0_size];
    byte[] buffer1_byte = new …
Run Code Online (Sandbox Code Playgroud)

android yuv pixelformat android-camera2

5
推荐指数
1
解决办法
2210
查看次数