我在 Java 中使用 Graphics2D 缩放对象时遇到问题。在我的paintComponent 中,我创建了两个graphics2D 对象以便于管理。然后我尝试缩放它们。问题是输出按 x4 缩放(缩放命令相互影响)。否则,一切都会呈现应有的效果。
这个怎么解决最好。
有问题的代码:
@Override
public void paintComponent(Graphics g) {
playerGraphics = (Graphics2D) g;
backgroundGraphics = (Graphics2D) g;
playerGraphics.scale(2.0, 2.0);
backgroundGraphics.scale(2.0, 2.0);
backgroundGraphics.drawImage(background.getBackground(), 0, 0, null);
for(int i = 0; i < noPlayers; i++) {
playerGraphics.drawImage(players.get(i).getCurrentSprite(), players.get(i).getXPos(), players.get(i).getYPos(), null);
}
}
Run Code Online (Sandbox Code Playgroud) 我想为我的 ImageView 构建一个放大和缩小动画,我设置了一个侦听器并将动画 RepeatCount 设置为无限。
首先,我从放大效果开始,然后在 onAnimationRepeat 方法中创建缩小部分,其中使用布尔值我想重新启动整个效果,开始再次放大。但是在第一次没有再次调用 onAnimationRepeat 之后,反过来动画正在重复但它卡在缩小部分。
我错过了什么?
//image animation
Animation anim = new ScaleAnimation(1.0f, 1.1f, 1.0f, 1.1f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(10000);
zoomIn = true;
// Start animating the image
final ImageView splash = (ImageView) findViewById(R.id.imageView);
splash.startAnimation(anim);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
if(zoomIn) {
Log.w("", "we zoom out, and zoomIn is: " + zoomIn);
Animation anim = new ScaleAnimation(1.1f, …
Run Code Online (Sandbox Code Playgroud) 我有这样的事情:
a <- c(1,4,2,8)
b <- c(100,80,40, 0)
c <- 1:4
x <- rep("foo",4)
y <- rep("bar",4)
df1 <- data.frame(c, y = a, gr = x)
df2 <- data.frame(c, y = b, gr = y)
df <- rbind(df1,df2)
xyplot(y ~ c, data = df, type = "l", group = df$gr)
Run Code Online (Sandbox Code Playgroud)
结果如下:
我正在寻找一种方法,允许我更改比例,以便蓝线填充整个面板区域,并在图的右侧添加相应的轴。
如果添加轴太难,那么就不是必需的。无论如何,y 轴上的单位是任意的(在我自己的数据中)。也许一种标准化数据的方法会起作用?
该网站上有几个答案,但它们都适用于 R 的基本图形,并且没有使用点阵。
我正在使用 Freetype 字体来显示文本。但字体总是看起来:#1不可读(通过减小字体大小):
generator = new FreeTypeFontGenerator(Gdx.files.internal("Fonts/LDFComicSans.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 5;
font = generator.generateFont(parameter); // font size 12 pixels
font.setColor(Color.BLACK);
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
generator.dispose();
Run Code Online (Sandbox Code Playgroud)
generator = new FreeTypeFontGenerator(Gdx.files.internal("Fonts/LDFComicSans.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 30;
font = generator.generateFont(parameter); // font size 12 pixels
font.setColor(Color.BLACK);
font.getData().setScale(0.15F, 0.15F);
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
generator.dispose();
Run Code Online (Sandbox Code Playgroud)
这些是我使用的相机/视口设置:
camera = new OrthographicCamera(1280, 720);
batch = new SpriteBatch();
viewport = new StretchViewport(100,100,camera);
viewport.apply();
Run Code Online (Sandbox Code Playgroud)
我认为这是因为视口太小,但我真的不想改变它。有谁知道如何解决这一问题?
我正在尝试应用水印,并通过 ffmpeg 命令将其缩放到当前视频大小:
这是我没有水印的初始命令
ffmpeg -v 0 -vcodec h264_qsv -i 'udp://@some.ip:1234?fifo_size=1000000&overrun_nonfatal=1&buffer_size=1000000' -vf scale=iw:ih -profile baseline -acodec aac -ac 1 -ar 44100 -ab 64k -deinterlace -vcodec h264_qsv -bufsize 4000k -maxrate 3500k -preset veryfast -vb 2000k -f flv rtmp://127.0.0.1/app/720
Run Code Online (Sandbox Code Playgroud)
现在我尝试将图片添加为水印。使用 with 时发生冲突-vf scale=-1:ih*.5
,为了消除我用来-s 1280x720
指定视频流分辨率的问题,它工作但不正常。
ffmpeg -v 0 -vcodec h264_qsv -i 'udp://@some.ip:1234?fifo_size=1000000&overrun_nonfatal=1&buffer_size=1000000' -i logo.png -filter_complex "overlay=10:10" -s 1280x720 -profile baseline -acodec aac -ac 1 -ar 44100 -ab 64k -deinterlace -vcodec h264_qsv -bufsize 4000k -maxrate 3500k -preset veryfast -vb 2000k …
Run Code Online (Sandbox Code Playgroud) 我正在使用这段代码:
ggplot2::ggplot(DATAFRAME, aes(x = as.factor(VARIABLE))) + ggplot2::geom_bar()
Run Code Online (Sandbox Code Playgroud)
绘制数据框 DATAFRAME 中变量 VARIABLE 每个级别的出现次数。然而,它是一个相当长的数据框,所以我希望计数以千为单位而不是单位。有人知道怎么做这个吗?
请参阅视觉辅助工具。gif 后面有两个 GUI。左侧的 GUI 根据相机到物体的距离进行适当缩放。右侧的 GUI 正在缩放,在“场景”视图中清晰可见,但在游戏视图中甚至不明显。该应用程序适用于 Hololens,因为用户头部在 Unity 场景中控制相机。
问题在于设置对象缩放比例。一整天我都在绞尽脑汁试图复制左侧 GUI 上显示的缩放类型。除以距离并将其用作缩放因子显然是不正确的,因为对象要么太大并且增长太快,要么太小并且增长太慢,但我不知道如何在中间的某个地方相遇。以明显但不令人讨厌的大或难以察觉的速率在两个方向上均匀地缩放。
到目前为止的实现代码:
// GameObject and GUI assigned in Editor
public GameObject sphere, rotationManager;
// For rotationManager scaling
private float cameraToObject,
void Update()
{
/* Scale rotationManager based on Cameras distance to object */
cameraToObject = Vector3.Distance(
sphere.transform.position,
Camera.main.transform.position);
Debug.Log("distance: " + cameraToObject);
// If camera isn't too close to our object
if (cameraToObject > 4f)
{
// adjust scale
rotationManager.transform.localScale = new Vector3(
cameraToObject / 5,
cameraToObject …
Run Code Online (Sandbox Code Playgroud) 我目前正在创建一个时间趋势图ggplot2
。我使用scale_x_date()
函数创建date_breaks
6 个月,并在每 6 个月标记一次,但图表 x 轴从 4 月开始,而不是从 1 月开始。
library(lubridate)
library(stats)
library(ggplot2)
dates <- seq.Date(mdy("01-01-2013"), mdy("01-01-2017"), by = "month")
value <- rnorm(length(dates))
data <- cbind.data.frame(dates, value)
plot <- ggplot(data, aes(x = dates, y = value)) +
geom_point() +
scale_x_date(date_breaks = "6 months",
date_labels = "%b\n%Y")
Run Code Online (Sandbox Code Playgroud)
输出 x 轴从 4 月开始。
我也尝试添加expand = c(0,0)
:
plot <- ggplot(data, aes(x = dates, y = value)) +
geom_point() +
scale_x_date(date_breaks = "6 months",
date_labels = …
Run Code Online (Sandbox Code Playgroud) 我必须确定图像是否是单色的。我的意思是单色不仅是黑色和白色..它可以是棕褐色,如红色或蓝色阴影,甚至混合红色和蓝色阴影(单色缩放)?
我认为我们可以说比例从黑色(0,0,0)到白色(255,255,255)但它不是线性的..它是每个颜色通道上的特定曲线
我希望我说得清楚:)