如何更改像素图中的特定颜色?例如,我有一个带有白色和黑色像素的像素图,我想将所有白色像素更改为蓝色,但不要将黑色像素单独保留.或者可能将黑色变为白色,白色变为蓝色...... [我在Qt/PyQt中搜索解决方案,但也许这是关于如何处理/合成像素图的一般问题.
我试图在LibGDX中将纹理转换为Pixmap,这样我就可以将所有像素数据放入ByteBuffer中进行一些实验,从我所知道的,我应该可以通过执行以下操作来实现:
Pixmap pixmap = textureName.getTexture().getTextureData().consumePixmap();
ByteBuffer data = pixmap.getPixels();
Run Code Online (Sandbox Code Playgroud)
这似乎返回一个大小合适的Pixmap,而ByteBuffer似乎确实创建得很好,但它完全用零填充,从而产生一个空白的透明图像.这个,以及其他一些测试,让我相信Pixmap本身只是被创建为一个完全透明的图像,但我找不到可能导致这种情况发生的原因.是否有某种限制阻止这种工作,或者我只是遗漏了一些明显的东西?
我想知道如何在Pixmap中获取FrameBufferPixel
我知道我必须使用getFrameBufferPixels(true)
但我不知道要放入什么参数
new Pixmap(byte[] encodedData, int offset, int len);
Run Code Online (Sandbox Code Playgroud)
你能告诉我一个应该工作的例子吗?
谢谢
我想在foreground纹理上叠加background纹理.除了这两个纹理,我还有一个mask指示前景的哪些部分应该是透明的.这是我试过的:
// Initially, the mask should have an alpha of 1
Pixmap mask = new Pixmap(128, 128, Pixmap.Format.Alpha);
// Cut a rectangle of alpha value 0
mask.setColor(new Color(0f, 0f, 0f, 0f));
mask.fillRectangle(0, 0, 32, 32);
// Load the foreground. The foreground should the same alpha values
// as the mask. If the mask has an alpha value of 1, then the foreground is
// visible. If the mask is 0, then the foreground is …Run Code Online (Sandbox Code Playgroud) 我需要在 Qt 中快速绘制小部件,但我不想使用任何准备好的东西。我有一些浮动数据,例如QVector< float >数据,我需要在小部件上绘制它。但我不希望使用paintEvent和QPainter直接就可以了。有没有机会将此数据转换为位图(像素图?)并直接加载它以显示在小部件上?如何从浮点数创建位图?
我的游戏中有大量的2D图像,有多层.我用spritebatch()和orthographicCamera().我有一些关于表演的基本问题:
Texture.draw(或Pixmap.draw用于Pixmap),制作最终图像然后渲染它吗?或者我应该在spritebatch.begin()和spritebatch.end()?感谢您的帮助(欢迎任何其他一般建议)
目标
目前我正在使用 libgdxPixmap创建一个健康栏,但是当我将drawLine参数更改为新值时,突然仍然没有任何更改。在下面的代码中是我当前的工作代码,我不确定这是否是Pixmap动态绘制的足够方法。
// This code is working when written all in update method
Pixmap frame = new Pixmap(32, 3, Pixmap.Format.RGBA8888);
frame.drawRectangle(...);
frame.drawLine(...);
Texture texture = new Texture(frame);
frame.dispose();
batch.begin();
batch.draw(texture ...);
batch.end();
Run Code Online (Sandbox Code Playgroud)
样本健康条
嘿,所以我有这个功能,它可以很好地工作和缩放图像,并且会根据 UI 中的正确快捷方式缩小和扩展它。
但是,当我缩放回图像的原始缩放比例时,我的图片质量会下降。我试过制作'orig',它是一个全局'const QPixmap*'。'orig' 是在图像加载到 UI 时定义的。然后我设置了 'pixmap = orig'(见下面的代码),但这似乎不起作用,我不知道为什么。
这个想法是在不重写原始像素图的情况下制作它的副本,以保持像素质量,然后在调用函数时重新加载原始像素图。
void FragTreeViewer::scaleImage(double factor)
{
Q_ASSERT(imageLabel->pixmap());
const QPixmap* pixmap = orig;
scaleFactor *= factor;
int w = (imageLabel->width())*scaleFactor;
int h = (imageLabel->height())*scaleFactor;
imageLabel->setPixmap(pixmap->scaled(w, h, Qt::KeepAspectRatio));
adjustScrollBar(scrollArea->horizontalScrollBar(), scaleFactor);
adjustScrollBar(scrollArea->verticalScrollBar(), scaleFactor);
//zoomInAct->setEnabled(scaleFactor < 3.0);
//zoomOutAct->setEnabled(scaleFactor > 0.333);
}
Run Code Online (Sandbox Code Playgroud)