我正在寻找这个,但我找不到任何东西。我的想法是我有一个像 (52.66, 60.11) 这样的 PointF,我想以此 PointF 为中心画一个空圆。我试图用 DrawEllipse 做,但它不关心中心!它只是一个矩形...我认为应该使用某种转换公式?
我有一个将在运行时生成的位图图像。我没有它的本地 url,因为它是在运行时以这种方式生成并返回给我的。有没有办法在运行时将此图像添加到 cshtml 文件或 html 文件?
public Bitmap GetBarcodeImage(string inputString)
{
Bitmap bitmap = new Bitmap(200,100);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);
graphics.DrawString(inputString, new Font("Free 3 of 9",60,FontStyle.Regular), Brushes.Black, new PointF(0, 0));
return bitmap;
}
Run Code Online (Sandbox Code Playgroud) 我知道有很多这样的问题,但他们的答案都不适合我,或者只是我无法正确完成,无论如何,如果可能的话,请给我一个简单的代码!
我知道绿点的位置,我想根据这个位置构造一个矩形。
例子:

最重要的是如何截取该区域的屏幕截图?
我不知道如何更改此代码以适合我的情况。
private Bitmap Screenshot()
{
Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bmpScreenshot);
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
return bmpScreenshot;
}
Run Code Online (Sandbox Code Playgroud) 我目前有以下方法
public void printTitle(string title){
// settings for stringformat
g.DrawString(title, drawFontTitle, Brushes.White, x, y, stringFormatTitle);
}
Run Code Online (Sandbox Code Playgroud)
但是,我试图让输入定义标题的颜色,如下所示:
public void printTitle(string title, Brushes titleColor){
// settings for stringformat
g.DrawString(title, drawFontTitle, titleColor, x, y, stringFormatTitle);
}
Run Code Online (Sandbox Code Playgroud)
它会像这样使用:
printTitle("Title Text", Brushes.White);
Brushes titleColor但是,我认为在声明导致错误时存在问题。
我当前的代码是将一个小的 Pbgra32 位图 blit'ing 到一个更大的 Pbgra32 位图上。工作正常。我现在想做的就是让那个较小的部分透明。为此,在 blit 之前,我将较小的值传递给一种方法,该方法应通过保留 RGB 值来编辑每个像素,同时将 0x7F 写入每个像素的 A 值。
然而,我得到的不是 50% 透明的图像,而是一个灰色的方块。我究竟做错了什么?
private void MakeTransparent(ref WriteableBitmap bmp)
{
int width = bmp.PixelWidth;
int height = bmp.PixelHeight;
int stride = bmp.BackBufferStride;
int bytesPerPixel = (bmp.Format.BitsPerPixel + 7)/8;
unsafe
{
bmp.Lock();
byte* pImgData = (byte*) bmp.BackBuffer;
int cRowStart = 0;
int cColStart = 0;
for (int row = 0; row < height; row++)
{
cColStart = cRowStart;
for (int col = 0; col < width; col++) …Run Code Online (Sandbox Code Playgroud) 我有一个尺寸为(宽度= 250,高度= 200)的位图图像。我用以下代码片段对其进行拉伸,但质量下降了。有没有办法在拉伸位图图像的同时保持其质量?
with Bitmap do
begin
Width := 200;
Height := 150;
PixelFormat := pf1bit;
TransparentMode := tmAuto;
Canvas.CopyMode := cmSrcCopy;
Canvas.FillRect(Rect(0, 0, Width, Height));
Canvas.StretchDraw(Rect(0, 0, Width, Height), MyBitMap);
end;
Run Code Online (Sandbox Code Playgroud)
这里,是我加载原始位图图像的MyBitMap类型。TBitMap
并且,这是这样做的正确方法吗?
我正在尝试将视图转换为位图,但我失去了黑色。我这样转换:
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(),view.getHeight(), Bitmap.Config.ARGB_8888);
Run Code Online (Sandbox Code Playgroud)
如何转换为位图以便百分比值的黑色不会丢失?
感谢和问候
我构建控制台应用程序来进行这样的测试。
while (true)
{
var bmp = new Bitmap(1600, 1200);
//var buffer = new byte[2000 * 1000 * 4];
Thread.Sleep(10);
}
Run Code Online (Sandbox Code Playgroud)
运行后,内存在很短的时间内增加到2GB以上。
这是 案例的日志Bitmap。
[2017-04-27 12:15:03][00:00:01.0150128] PrivateBytes : 1583.0MB, AllHeapsBytes : 0.0MB, Thread Count : 23, CPU Usage : 12%
[2017-04-27 12:15:04][00:00:02.0019966] PrivateBytes : 2150.0MB, AllHeapsBytes : 0.0MB, Thread Count : 24, CPU Usage : 10%
[2017-04-27 12:15:05][00:00:03.0030021] PrivateBytes : 500.0MB, AllHeapsBytes : 4.1MB, Thread Count : 24, CPU Usage : 26%
[2017-04-27 12:15:06][00:00:04.0040047] PrivateBytes : 1043.0MB, AllHeapsBytes …Run Code Online (Sandbox Code Playgroud) 我尝试了很长时间也没有更好的办法,在不同的手机上:
1.我想在sourceBitmap中添加图片和文字。
2.希望能够调整位图和字的位置。
位图压缩过程需要太多时间。我该如何解决这个问题?
在活动中:
icon= BitmapFactory.decodeResource(getResources(),R.mipmap.image);
Run Code Online (Sandbox Code Playgroud)
在回调类中:
synchronized (holder) {
stream = new ByteArrayOutputStream();
Log.d("LIFE_CYCLE", "settingImage 1=" + System.currentTimeMillis());
icon.compress(Bitmap.CompressFormat.PNG, 100, stream);
Log.d("LIFE_CYCLE", "settingImage 2=" + System.currentTimeMillis());
byteArray = stream.toByteArray();
b = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
if(mWidth<mHeight){
icon= Bitmap.createScaledBitmap(b, (int)(mWidth*0.75), (int)(mWidth*0.75), false);
}
else{
icon= Bitmap.createScaledBitmap(b, (int)(mHeight*0.75), (int)(mHeight*0.75), false);
}
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawBitmap(icon, ((mWidth)-icon.getWidth())/2, (mHeight-icon.getHeight())/2, new Paint());
draw_target(canvas);
}
Run Code Online (Sandbox Code Playgroud)
此行大约需要 2 秒:
icon.compress(Bitmap.CompressFormat.PNG, 100, stream);
Run Code Online (Sandbox Code Playgroud)
PS我的图像是部分透明的,所以我需要使用.PNG而不是.JPG
bitmap ×10
c# ×5
android ×3
canvas ×2
asp.net ×1
asp.net-mvc ×1
barcode ×1
bitmapimage ×1
colors ×1
delphi ×1
delphi-xe4 ×1
draw ×1
geometry ×1
graphics ×1
layout ×1
picturebox ×1
rectangles ×1
screenshot ×1
view ×1