C# / .NET 有没有办法将 VML 渲染成位图?
我认为这应该很容易,但我似乎在 .NET 文档中找不到类似的内容。
当使用 Graphics 单元中的 GDI 位图的 TBitmap 包装器时,我注意到在使用 SetSize( w, h ) 设置位图时,它总是会清除位图(使用 PatBlt 调用)。当我稍后复制这些位时(参见下面的例程),似乎 ScanLine 是最快的可能性,而不是 SetDIBits。
function ToBitmap: TBitmap;
var
i, N, x: Integer;
S, D: PAnsiChar;
begin
Result := TBitmap.Create();
Result.PixelFormat := pf32bit;
Result.SetSize( width, height );
S := Src;
D := Result.ScanLine[ 0 ];
x := Integer( Result.ScanLine[ 1 ] ) - Integer( D );
N := width * sizeof( longword );
for i := 0 to height - 1 do begin
Move( S^, D^, N ); …Run Code Online (Sandbox Code Playgroud) 我最近也收到了同样的 ANR 报告。当应用程序尝试绘制一些位图时(使用 ImageView 作为元素渲染 GridView 时),会发生 ANR。我已经做了很多调试,现在可以肯定地说挂起既不依赖于位图,也不依赖于它的绘制位置。
堆是 50% 自由的,图像不大于 400px^2
网格元素没有任何自定义布局 - 只是简单的 ImageView。
在 HTC Desire(1 GHz CPU)、Hero、模拟器等上进行了测试
。ANR 会永远持续下去,因此就像在绘制位图时正在运行某些无限循环。
还有什么会导致这样的挂起?
报告如下:
DALVIK THREADS:
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 s=N obj=0x40020ba0 self=0xddd0
| sysTid=32366 nice=0 sched=0/0 cgrp=unknown handle=-1345025972
at android.graphics.Canvas.native_drawBitmap(Native Method)
at android.graphics.Canvas.drawBitmap(Canvas.java:1045)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:323)
at android.widget.ImageView.onDraw(ImageView.java:860)
at android.view.View.draw(View.java:6740)
at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
at android.view.View.draw(View.java:6743)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
at android.view.View.draw(View.java:6743)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1847)
at …Run Code Online (Sandbox Code Playgroud) 我想问这个之前被问过几次的问题。抱歉,如果我重复一遍,但我不清楚这里最好的解决方案是什么。
问题是“如何在使用 ImageView 位图资源后清理它,这样我们就不会在内存中引用它?”。
这是一个例子:
第一次一切正常。控件 A 完成后,我从屏幕 2 重定向到屏幕 1。此时,其使用的控件 A 或 ImageView B 或位图的所有引用都应该已失效。他们不是!!!
我尝试过各种解决方案,包括 bitmap.recycle()、将 Finalize() 添加到 Control A、System.gs() 以及在不同位置(例如 onStop() 和 onDestroy())以及屏幕上显示的所有其他内容清空控件2、没有任何作用!
问题是,当我第二次重新访问屏幕时,从屏幕 1 到屏幕 2(即再次创建照片预览)时,我会出现内存不足异常。据我了解,之前位图的引用没有被清除。
如何在重定向回屏幕 1 之前杀死它?
我注意到一件事。如果我通过裁剪或缩小图像尺寸来减小照片的尺寸,一切都会变得顺利,几次......在我遇到同样的问题之前。所以基本上只是需要更长的时间才能充满。
我真的很感激这里的一些解决方案,因为这很关键。
我在使用 SurfaceView 时遇到了一些帧速率问题。我正在做我在一些教程中找到的典型内容(所有教程都说一样),但我无法在我的三星 Galaxy S(旧款 i9000)上达到像样的帧速率。
这是我的循环线程的代码。FPS 初始化为 30。
@Override
public void run() {
long ticksPS = 1000/FPS;
long startTime;
long sleepTime;
//fps checker
long contms=0;
long lasttimecheck = System.currentTimeMillis();
int fps=0;
while (running) {
long time = System.currentTimeMillis();
if(contms>1000) {
Log.v("FPS",String.valueOf(fps));
contms=time-lasttimecheck;
fps=1;
}
else {
fps++;
contms+=time-lasttimecheck;
}
lasttimecheck = time;
Canvas c = null;
startTime =time;
try {
c = view.getHolder().lockCanvas();
synchronized (view.getHolder()) {
view.onDraw(c);
}
} finally {
if (c != null) {
view.getHolder().unlockCanvasAndPost(c);
}
} …Run Code Online (Sandbox Code Playgroud) 我正在从具有以下内容的文件加载 DIBSection:
HBITMAP bmpIn = (HBITMAP) LoadImage(NULL, _T("c:\\Temp\\Temp.bmp"), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
Run Code Online (Sandbox Code Playgroud)
根据经验,我发现加载的位图和我过去使用的位图之间存在以下差异,但我找不到任何文档说明应该存在差异。
CreateDIBSection当您使用从头开始创建 DIBSection时,我还发现了一个已记录的差异。
GetObject将为 NULL。前两个差异的文档在哪里,我是否遗漏了什么?这是 Windows 7 的情况,但我无法想象其他版本的 Windows 会有什么不同。
编辑:一些额外的细节。这是一个十六进制转储temp.bmp;它是一个 7x7 的图像,右侧有白色条纹,蓝色值沿左侧递增(0x10、0x20 等)。您可以看到底线 (00,00,70) 位于第一行,并且有 3 个字节的填充。
00: 42 4d de 00 00 00 00 00 00 00 36 00 00 00 28 00
10: 00 00 07 00 00 00 07 00 00 00 01 …Run Code Online (Sandbox Code Playgroud) 我找到了有关如何在 C# 中将颜色滤镜应用于位图对象的代码。它的问题是它使用不安全的代码来完成此操作。有没有一种托管的、安全的方法来做同样的事情?我知道我可以使用 AForge.NET 或类似的库,但我希望有一种简单的方法来应用颜色滤镜。我需要的只是简单的颜色替换,用黄色替换白色像素。有什么建议么?
我正在尝试在 中创建位图数据,这是我使用的代码,但我无法找出正确的逻辑。这是我的代码
bool a=1;
bool b=0;
bool c=1;
bool d=0;
uint8_t output = a|b|c|d;
printf("outupt = %X", output);
Run Code Online (Sandbox Code Playgroud)
我希望我的输出是“1010”,相当于十六进制“0x0A”。我该怎么做 ??
我正在使用自定义 TextView 绘制文本垂直,来自 MPAndroidCharts 库的图形和图形顶部的文本视图。虽然它在屏幕上看起来很棒,但当我尝试获取它的位图以便将其作为图像共享时,获得的垂直文本视图并未完全绘制。
我的视图 XML 如下:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/clWeatherCharts">
<TextView
android:id="@+id/txtWeatherTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="@dimen/margin_16dp"
android:text="@string/temperature_registers"
android:textAlignment="center"/>
<com.shadows.naylapp.utils.VerticalTextView
android:id="@+id/llYEnvironment"
android:textColor="@color/colorBlack"
android:textSize="14sp"
android:layout_width="20dp"
android:layout_height="0dp"
android:text="Temperatura Superficial del Mar (Cº)"
android:layout_margin="@dimen/padding_8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/lineWeatherChart"
app:layout_constraintBottom_toBottomOf="@id/lineWeatherChart"
/>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/lineWeatherChart"
android:layout_marginTop="@dimen/margin_16dp"
android:layout_width="0dp"
android:layout_height="300dp"
app:layout_constraintEnd_toStartOf="@id/llYWindEnvironment"
app:layout_constraintStart_toEndOf="@id/llYEnvironment"
app:layout_constraintTop_toBottomOf="@id/txtWeatherTitle" />
<LinearLayout
android:id="@+id/llYWindEnvironment"
android:layout_width="20dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/lineWeatherChart"
app:layout_constraintBottom_toBottomOf="@id/lineWeatherChart">
<com.shadows.naylapp.utils.VerticalTextView
android:textColor="@color/colorBlack"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Velocidad del Viento (Km/hr)"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我正在使用扩展函数来创建位图,如下所示:
fun View.getBitmapFromView(): Bitmap? {
val bitmap = Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888) …Run Code Online (Sandbox Code Playgroud)