这是什么原因?
我重写OnPaintBackground并绘制一个字符串.直到我在构造函数中调用它才会显示:
this.SetStyle ( ControlStyles.UserPaint, true );
Run Code Online (Sandbox Code Playgroud)
但后来我没有在列表视图中看到这些项目.
为什么以及如何解决这个问题?
编辑:代码
protected override void OnPaintBackground ( PaintEventArgs pevent )
{
base.OnPaintBackground ( pevent );
// Create string to draw.
String drawString = "76";
// Create font and brush.
Font drawFont = new Font ( "Arial", 36 );
SolidBrush drawBrush = new SolidBrush ( Color.Blue );
// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF ( 150.0F, 150.0F );
// Draw string to screen.
pevent.Graphics.DrawString ( drawString, drawFont, …Run Code Online (Sandbox Code Playgroud) 我正在寻找一些像GDI +这样不需要运行时库的单元.我只需要文字和图像效果.
我使用以下代码根据EXIF数据修复图像的方向
Image FixImageOrientation(Image srce)
{
const int ExifOrientationId = 0x112;
// Read orientation tag
if (!srce.PropertyIdList.Contains(ExifOrientationId)) return srce;
var prop = srce.GetPropertyItem(ExifOrientationId);
var orient = BitConverter.ToInt16(prop.Value, 0);
// Force value to 1
prop.Value = BitConverter.GetBytes((short)1);
srce.SetPropertyItem(prop);
// MessageBox.Show(orient.ToString());
// Rotate/flip image according to <orient>
switch (orient)
{
case 1:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
return srce;
case 2:
srce.RotateFlip(RotateFlipType.RotateNoneFlipX);
return srce;
case 3:
srce.RotateFlip(RotateFlipType.Rotate180FlipNone);
return srce;
case 4:
srce.RotateFlip(RotateFlipType.Rotate180FlipX);
return srce;
case 5:
srce.RotateFlip(RotateFlipType.Rotate90FlipX);
return srce;
case 6:
srce.RotateFlip(RotateFlipType.Rotate90FlipNone);
return srce;
case 7:
srce.RotateFlip(RotateFlipType.Rotate270FlipX); …Run Code Online (Sandbox Code Playgroud) 所以我想制作一个廉价的Gyazo副本(截图工具)
问题是光标坐标是闪烁的,我该如何防止?我已经尝试过,WM_ERASEBKGND但它没有任何帮助.
我的代码还有什么问题吗?任何不良做法/技巧?
#include <Windows.h>
#include <string>
#include <gdiplus.h>
#pragma comment (lib, "Gdiplus.lib")
// Store the "screenshot" when first launching the program
HBITMAP hbm;
// This draws the cursor coordinates close to the cursor
void DrawCursorCoords(Gdiplus::Graphics &graphics, Gdiplus::Bitmap &bitmap, Gdiplus::Color c)
{
POINT cursorPos;
GetCursorPos(&cursorPos);
std::wstring x = std::to_wstring(cursorPos.x);
std::wstring y = std::to_wstring(cursorPos.y);
graphics.DrawString(x.c_str(), x.length(), &Gdiplus::Font(L"Consolas", 16), Gdiplus::PointF(cursorPos.x, cursorPos.y), &Gdiplus::SolidBrush(c));
graphics.DrawString(y.c_str(), y.length(), &Gdiplus::Font(L"Consolas", 16), Gdiplus::PointF(cursorPos.x, cursorPos.y + 16), &Gdiplus::SolidBrush(c));
}
// Paint our stuff
void Paint(HDC &hdc)
{ …Run Code Online (Sandbox Code Playgroud) 我有一百张 JPG 图像,想将它们合并为一个大 JPG。为了实现这一点,我使用以下代码:
using (var combinedBitmap = new Bitmap(combinedWidth, combinedHeights)) {
combinedBitmap.SetResolution(96, 96);
using (var g = Graphics.FromImage(combinedBitmap))
{
g.Clear(Color.White);
foreach (var imagePiece in imagePieces)
{
var imagePath = Path.Combine(slideFolderPath, imagePiece.FileName);
using (var image = Image.FromFile(imagePath))
{
var x = columnXs[imagePiece.Column];
var y = rowYs[imagePiece.Row];
g.DrawImage(image, new Point(x, y));
}
}
}
combinedBitmap.Save(combinedImagePath, ImageFormat.Jpeg);
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,直到尺寸(combinedWidth,combinedHeights)超过窗帘阈值,就像这里所说的 /sf/answers/2042313381/
尺寸为 23170 x 23170 像素的合并 JPG 文件大约为 50MB — 不会太大而无法占用内存。
但是位图不能用更大的维度创建——只是因为错误的参数异常而中断。
有没有其他方法可以使用 C# 将 JPG 图像块合并到一个尺寸大于 23170 x …
我已经在这个程序上工作了大约一个月了,尝试了一切。无论我做什么,我的程序都会闪烁,即使在其他机器上也是如此。它只是一个背景、一个图像和一个矩形。没有什么大的或昂贵的。然而它仍然闪烁。我试过将 DoubleBuffered 设置为 true,我试过覆盖 CreateParams(它使我的窗口变黑),我试过使用反射的方法,我试过 SetStyle 来设置 DoubleBuffer、OptimizedDoubleBuffer、UserPaint、AllPaintingInWmPain 和 Opaque当设置为 true 时,他们都没有做任何事情。我已经在 google 和 stackoverflow 上搜索了答案,但没有一个起作用。我无法理解我做错了什么。我添加了代码、exe、编译脚本和图像的 zip。我和其他人的计算机上发生的事情就是 gif 上的内容。该程序每秒更新 4 次,足以绘制背景、图像和正方形的时间,但它仍然闪烁。请我需要帮助。
主文件:
using System;
using System.Threading;
using System.Windows.Forms;
public class main{
public static void Main(string[] args){
Console.WriteLine("START");
Engine.Init();
while(true){
Engine.MainDraw();
Application.DoEvents();
Thread.Sleep(250);
}
Console.WriteLine("END");
}
}
Run Code Online (Sandbox Code Playgroud)
引擎.cs:
using System;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using System.Drawing;
public class Engine : Form{
public static Engine EngineForm = new Engine();
public static Graphics g;
/*
protected override CreateParams CreateParams{
get{
CreateParams …Run Code Online (Sandbox Code Playgroud) 我有一个创建大位图的应用程序,之后用户可以添加一些标签.只要基本位图是默认的96x96分辨率,一切都很好.例如,如果我将它提升到300,那么使用Graphics.DrawString应用的文本太大了 - 小尺寸的8或10字体显示就像是20.
一方面,鉴于分辨率增加,它是有道理的,但另一方面,你认为字体会扩展.当在300 vs 96 dpi位图上测量时,MeasureString返回更大的尺寸,这实际上不是我所期望的.
我尝试通过创建一个适当大小的小位图,打印到它,然后粘贴到主图像来欺骗它.但是当粘贴到高分辨率时,它会放大粘贴的图像.
我能想到的唯一另一件事是创建一个高分辨率的临时位图,打印到它,然后在粘贴到主图像之前缩小它.这似乎还有很长的路要走.是否有允许这样的合成或叠加类型设置?字体大小仅适用于96 dpi画布吗?
感谢任何提示/建议!
有人可以解释Graphics传递的对象pevent.Graphics和调用返回的对象之间的区别this.CreateGraphics()吗?