我正在使用一个NSView来托管几个Core Animation CALayer对象.我想要做的是抓取视图当前状态的快照作为位图图像.
这是相对简单的,正常NSView使用这样的东西:
void ClearBitmapImageRep(NSBitmapImageRep* bitmap) {
unsigned char* bitmapData = [bitmap bitmapData];
if (bitmapData != NULL)
bzero(bitmapData, [bitmap bytesPerRow] * [bitmap pixelsHigh]);
}
@implementation NSView (Additions)
- (NSBitmapImageRep*)bitmapImageRepInRect:(NSRect)rect
{
NSBitmapImageRep* imageRep = [self bitmapImageRepForCachingDisplayInRect:rect];
ClearBitmapImageRep(imageRep);
[self cacheDisplayInRect:rect toBitmapImageRep:imageRep];
return imageRep;
}
@end
Run Code Online (Sandbox Code Playgroud)
但是,当我使用此代码时,不会渲染Core Animation图层.
我已经调查了CARenderer,因为它似乎做了我需要的东西,但是我无法让它渲染我现有的图层树.我尝试了以下方法:
NSOpenGLPixelFormatAttribute att[] =
{
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFANoRecovery,
NSOpenGLPFAAccelerated,
0
};
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:att];
NSOpenGLView* openGLView = [[NSOpenGLView …Run Code Online (Sandbox Code Playgroud) 我正在尝试修改标准的Swing JTree以使用和不使用复选框来混合节点.这是一个例子:

当我尝试选中/取消选中其中一个复选框(本例中为"User 01"节点)时,树会丢失节点:

我的代码是这个例子的改编:http://forums.sun.com/thread.jspa?threadID = 5321084&start = 13.
而不是像这样在DefaultMutableTreeNode中嵌入JCheckBox:
new DefaultMutableTreeNode(new CheckBoxNode("Accessibility", true));
Run Code Online (Sandbox Code Playgroud)
我认为创建一个派生自DefaultMutableTreeNode的模型节点更有意义,我称之为JTreeNode.该类自动将DefaultMutableTreeNode的UserObject设置为JCheckBox.TreeCellRenderer使用类的ShowCheckBox属性来确定是否使用了JCheckBox或DefaultTreeCellRenderer.JTreeNode的用法如下:
JTreeNode user01 = new JTreeNode("User 01");
user01.setShowCheckBox(true);
user01.setSelected(true);
Run Code Online (Sandbox Code Playgroud)
我认为问题在于实现TreeCellEditor的类,特别是在getCellEditorValue()或getTreeCellEditorComponent()方法中.我怀疑这个问题与getCellEditorValue()有关,返回DefaultMutableTreeNode的派生,而不是更简单的模型实例.
public Object getCellEditorValue() {
JCheckBox checkBox = renderer.getCheckBoxRenderer();
JTreeNode node = new JTreeNode(checkBox.getText());
node.setShowCheckBox(true);
node.setSelected(checkBox.isSelected());
return node;
}
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
Component editor = renderer.getTreeCellRendererComponent(tree, value, true, expanded, leaf, row, true);
// editor always selected / focused
ItemListener itemListener = …Run Code Online (Sandbox Code Playgroud) 我正在运行Ruby on Rails 3,我想渲染一个show.html.erb传递局部变量的template().
在RAILS_ROOT/views/users/show.html.erb我有
Name: <%= @user.name %>
Surname: <%= @user.surname %>
Run Code Online (Sandbox Code Playgroud)
我也有一个页面控制器来处理页面中和application_controller.rb的istance @current_user.一个页面被调用user,所以RAILS_ROOT/views/pages/user.html.erb我有
<%= render :template => "users/show", :locals => { :user => @current_user } %>
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用(我得到这个错误RuntimeError in Pages#user, Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id:)但这有效:
<%= render :template => "users/show", :locals => { :user => @user = @current_user } %>
Run Code Online (Sandbox Code Playgroud)
我认为这不是 …
我有Flutter(Dart)RenderFlex溢出像素的问题.渲染库的一个例外.
如何管理或应用滚动功能到我的应用页面视图,并避免Flutter使用以下消息呈现异常:
RenderFlex底部溢出28像素.
如果你有任何机会需要完整的日志来帮助我在这里:
在热重载时,它根据消息在底部出现黄色/黑色条纹.
这是我可以使用可滚动小部件管理的东西吗?或者我可以声明我的小部件以控制它?
完整代码,如果需要(我更改了文本数据,但假设出现的文本长于屏幕大小,因此出现错误):
@override
Widget build(BuildContext context) {
return new DefaultTabController(
length: 3,
child: new Scaffold(
appBar: new AppBar(
bottom: new TabBar(
tabs: [
new Tab(text: "xxx",),
new Tab(text: "xxx",),
new Tab(text: "xxx",),
],
),
title: new Text(data["xxx"]),
),
body: new TabBarView(
children: [
new Column(
children: <Widget>[
new Text(data["xxx"],
style: new TextStyle(
fontStyle: FontStyle.italic,
color: Colors.blue,
fontSize: 16.0
),),
new Text(data["xxx"],
style: new TextStyle(
fontStyle: FontStyle.italic,
color: Colors.blue,
fontSize: 10.0
),),
new Text(data["xxx"],
style: new …Run Code Online (Sandbox Code Playgroud) 除了浏览器缓存之外,还有一些浏览器缓存数据的方式.对于Chrome,渲染引擎Blink中还有另一个缓存,可将图像,样式,脚本和字体(可能更多)存储在内存中.
此缓存用于站点上的连续导航.从Blink缓存传递的资源(from memory cache)在网络选项卡中标记.从浏览器缓存提供的资源标记为(from disk cache).
我现在的问题是,哪些资源存储在这个非常快的缓存中?从我的测试来看,它变化很大:
磁盘缓存命中和内存缓存命中之间的一个巨大差异与Service Workers结合使用.在服务工作者中无法观察到由内存缓存提供的请求(因为缓存位于服务工作者之前).磁盘缓存提供的请求通过Service Worker(因为浏览器缓存位于Service Worker后面).
为了显示解释的行为,我构建了一个包含所有资源类型的测试页面:https://dm-clone-optimized.app.baqend.com/
您可以使用顶部的链接浏览站点,并观察请求在网络选项卡和控制台中的行为方式.每个页面加载相同的资源.
经过一些导航(Chrome 70.0.3538.67)之后,我大部分时间都会遇到这种情况:

scripts.js,并scripts2.js从内存中缓存logo.png也来自内存styles.css来自磁盘缓存 :(scripts2.js?id=1也来自磁盘缓存 :(我很想了解Blink内存缓存是如何工作的,以及如何调整我的网站以将其用于具有适当cache control标头的所有资源.
----编辑----
最让我担心的是:为什么动态添加的脚本根本没有缓存?这对框架有明显的影响,scripts.js因为它们将所有依赖项作为动态添加的脚本标记插入.
我一直在尝试增强我用Java编写的GUI系统以使用子像素抗锯齿并且已经成功,除了两个剩余的异常.这是几个星期前我的另一个问题的后续问题.
第一个问题是将设置渲染提示KEY_ANTIALIASING设置为VALUE_ANTIALIAS_ON会导致KEY_TEXT_ANTIALIASING在设置为LCD(子像素)AA值时被忽略.任何人都可以对此有所了解吗?目前我在渲染文本之前被迫使用VALUE_ANTIALIAS_OFF,并在渲染文本后将其重新打开(以便其他绘画,如圆圈等,是AA'd).下面的独立测试程序证明了这个问题.
第二个问题是我找不到查询AA的底层操作系统设置,所以我必须做一个相当大的解决方法,即创建一个Swing JLabel,获取它的FontMetrics,得到它的FontRenderContext然后得到AA提示.除了在一个程序中涉及Swing,否则完全不使用Swing,它将无法在运行任何J2ME JVM的设备上运行.任何人都可以提出更好的方法吗?如果它需要J5或J6就可以了,因为当前的kludge已经需要J6(但只需要J4就是最好的).我已经尝试了每个默认设置并使用AWT组件而不是JLabel.
该程序验证要使子像素AA工作,必须首先禁用一般AA设置.(PS:我写入后台缓冲区,因为我的底层GUI确实如此,我想在等效的上下文中进行测试).
import java.awt.*;
import java.awt.event.*;
public class AwtTestFrame1b extends Panel {
private final Font font=new Font(Font.SANS_SERIF, Font.PLAIN, 16);
private final int line=25;
AwtTestFrame1b() {
setBackground(SystemColor.control);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
int py=0;
py=paintText(g2d,py,null ,false);
py=paintText(g2d,py,null ,true );
py+=line;
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF ,false);
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT ,false);
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_ON ,false);
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_GASP ,false);
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,false);
py+=line;
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF ,true );
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT ,true );
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_ON ,true );
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_GASP ,true );
py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,true );
py+=line; …Run Code Online (Sandbox Code Playgroud) 有没有人曾尝试使用Swing构建一个合适的多缓冲渲染环境,在此环境中可以添加Swing用户界面元素?
在这种情况下,我有一个动画红色矩形绘制在背景上.背景不需要每帧更新,因此我将其渲染到BufferedImage上,并仅重绘清除矩形的先前位置所需的部分.请参见下面的完整代码,这扩展了以前的线程通过@trashgod给出的例子,在这里.
到现在为止还挺好; 流畅的动画,低CPU使用率,无闪烁.
然后我将JTextField添加到Jpanel(通过单击屏幕上的任何位置),并通过在文本框内单击来关注它.现在,清除矩形的先前位置会在每个光标闪烁时失败,请参见下图.
我很好奇是否有人知道为什么会发生这种情况(Swing不是线程安全的?图像是异步绘制的?)以及寻找可能解决方案的方向.
这是在Mac OS 10.5,Java 1.6上
JPanel重绘失败了http://www.arttech.nl/javaredrawerror.png
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Transparency;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;
public class NewTest extends JPanel implements
MouseListener,
ActionListener,
ComponentListener,
Runnable
{
JFrame f;
Insets insets;
private Timer t = new Timer(20, …Run Code Online (Sandbox Code Playgroud) 在IE9中看一下这个:
http://jsfiddle.net/dalgard/n6PDB/show/
屏幕转储:

阅读这些评论:
/*
* IE9: Upon moving the mouse a ghostly 1px vertical line appears 53px into the
* blue area - only works with normalized CSS (!?) and not inside an iframe
*/
#test {
width: 152px; /* must be 152px or larger! */
height: 200px; /* can be any height */
border-radius: 1px; /* must be 1px or larger */
background-color: #44f; /* ghost-line becomes invisible with #00f */
}
#test:hover {} /* removing this makes …Run Code Online (Sandbox Code Playgroud) 目前我使用45度角为我的gluPerspective().这是正确的角度,使渲染在人类感知它时看起来真实吗?窗口纵横比也存在问题,例如2:1窗口将使得45度角看起来更像是具有3:4比例等的屏幕上的80度角.因此窗口尺寸也改变了视角.
那么,与人类如何看待世界相比,使游戏看起来最真实的窗口大小比例和视角是多少?
我是blender和python的新手.我有一个搅拌器模型(.blend),我想批量渲染为几个图像,为每个图像提供一些属性.
我用这些参数编写了一个python脚本,如:
import bpy
pi = 3.14159265
fov = 50
scene = bpy.data.scenes["Scene"]
# Set render resolution
scene.render.resolution_x = 480
scene.render.resolution_y = 359
# Set camera fov in degrees
scene.camera.data.angle = fov*(pi/180.0)
# Set camera rotation in euler angles
scene.camera.rotation_mode = 'XYZ'
scene.camera.rotation_euler[0] = 0.0*(pi/180.0)
scene.camera.rotation_euler[1] = 0.0*(pi/180.0)
scene.camera.rotation_euler[2] = -30.0*(pi/180.0)
# Set camera translation
scene.camera.location.x = 0.0
scene.camera.location.y = 0.0
scene.camera.location.z = 80.0
Run Code Online (Sandbox Code Playgroud)
那么我就像运行它一样
blender -b marker_a4.blend --python "marker_a4.py" -o //out -F JPEG -x 1 -f 1
Run Code Online (Sandbox Code Playgroud)
然后,例如,如果我尝试使用python脚本的参数
... …Run Code Online (Sandbox Code Playgroud) rendering ×10
java ×3
swing ×2
antialiasing ×1
batch-file ×1
bitmap ×1
blender-2.50 ×1
buffering ×1
caching ×1
cocoa ×1
css ×1
dart ×1
fieldofview ×1
flutter ×1
fonts ×1
jcheckbox ×1
jtree ×1
mobile ×1
objective-c ×1
opengl ×1
overflow ×1
python ×1
ruby ×1
templates ×1