小编Rag*_*aer的帖子

将列表格式化为字符串

所以即使我的代码运行一个小问题,我怎么能将我的List转换为这种格式的普通字符串

listitem1, listitem2, listitem3
Run Code Online (Sandbox Code Playgroud)

请注意,最后一个listitem3最后没有.

我试过String.Inser,但我不能得到最后一个索引..

c# string list

2
推荐指数
1
解决办法
81
查看次数

转到 base64 图像解码

我目前正在从类似这样的画布中获取 base64 图像数据 url(不是我获取的 dataurl 只是为了显示字符串的样子)

data:image/png;base64,iVkhdfjdAjdfirtn=
Run Code Online (Sandbox Code Playgroud)

我需要解码该图像以检查图像的宽度和高度

    dataurl := strings.Replace(req.PostFormValue("dataurl"), "data:image/png;base64,", "", 1)

    reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(dataurl))
    c, _, err := image.DecodeConfig(reader)
    if err != nil {
        log.Fatal(err)
    }
    log.Println(c.Width)
Run Code Online (Sandbox Code Playgroud)

但是我在尝试解码配置时遇到错误

Unknown image format
Run Code Online (Sandbox Code Playgroud)

所以是的,我制作 dataurl 的方式一定是错误的,但不知道该怎么做。我也试过传递完整的 dataurl (with data:image...) 仍然没有成功

base64 image go

2
推荐指数
1
解决办法
4376
查看次数

去图像处理

我需要加载图像并搜索颜色并替换它们。例如,在图像上,我需要搜索所有红色像素并将其转换为紫色。

我正在执行以下操作(img是有效的.png图像):

func colorize(img image.Image) {
    b := image.NewRGBA(img.Bounds())
    draw.Draw(b, b.Bounds(), img, image.ZP, draw.Src)
    for x := 0; x < b.Bounds().Dx(); x++ {
        for y := 0; y < b.Bounds().Dy(); y++ {
            log.Println(b.At(x, y).RGBA())
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

事情是img.At().RGBA()似乎没有返回正确的R,G,B,A码?例如,我得到的数字大于255。

因此,如何读取所有图像像素,同时又能知道它们的x和y位置?

image colors go rgba

2
推荐指数
1
解决办法
431
查看次数

去goroutine锁定和解锁

我一直在阅读goroutines和同步包,我的问题是......在读取不同goroutine上的数据时,我是否总是需要锁定解锁?

例如,我的服务器上有一个变量

config := make(map[string]string)
Run Code Online (Sandbox Code Playgroud)

然后在不同的goroutines上我想从配置中读取.不使用同步读取是否安全,或者不是?

我想使用同步包需要完成写入.但我不确定阅读

例如,我有一个简单的内存缓存系统

type Cache interface {
    Get(key string) interface{}
    Put(key string, expires int64, value interface{})
}

// MemoryCache represents a memory type of cache
type MemoryCache struct {
    c map[string]*MemoryCacheValue
    rw sync.RWMutex
}

// MemoryCacheValue represents a memory cache value
type MemoryCacheValue struct {
    value interface{}
    expires int64
}

// NewMemoryCache creates a new memory cache
func NewMemoryCache() Cache {
    return &MemoryCache{
        c: make(map[string]*MemoryCacheValue),
    }
}

// Get stores something into the cache
func …
Run Code Online (Sandbox Code Playgroud)

synchronization go

1
推荐指数
1
解决办法
2201
查看次数

方法的返回类型的目的

我在理解C#方法的语法时遇到了问题 - 特别是"must return something"错误.

我有这个方法:

public static class Connection
{
    public static List<string> getClients()
    {   
        List<string> clients = new List<string>();
        return clients;
    }
}
Run Code Online (Sandbox Code Playgroud)

因为我得到了这个方法不正确invalid expression term "return",所以我不知道该怎么做.有人可以解释一下这个公共空白等是如何起作用的吗?

另外,为什么我不能做以下事情?

public getClients()
    {   
        List<string> clients = new List<string>();
        return clients;
    }
Run Code Online (Sandbox Code Playgroud)

我收到一个错误说 method must have a return type

c# methods return

0
推荐指数
1
解决办法
272
查看次数

获取设置属性

所以我试图在C#上使用get/set属性,但我无法让我的代码工作(它崩溃我的控制台应用程序)

这是我的textHandler.cs文件,你可以看到public static void方法WriteInfo正在使用get/set属性但它崩溃了我的应用程序..

class TextHandler
{
    public static void WriteInfo(String text)
    {
        var consoleText = new Text();
        consoleText.text = text;
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.WriteLine(consoleText);
        Console.ForegroundColor = ConsoleColor.White;
    }
    public static void WriteError(String text)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(text);
        Console.ForegroundColor = ConsoleColor.White;
    }
    public static void WriteSuccess(String text)
    {
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine(text);
        Console.ForegroundColor = ConsoleColor.White;
    }
    public static void WriteText(String text, ConsoleColor color)
    {
    }
}
public class Text
{
    public String text
    {
        get
        {
            return this.text;
        } …
Run Code Online (Sandbox Code Playgroud)

c# get set

0
推荐指数
1
解决办法
2686
查看次数

Laravel 文件上传

出现以下错误

无法创建“ http://website.com/public/uploads/ ”目录

我的代码:

$file = Input::file('upload');
$file_name = $file->getClientOriginalName();
$file_size = round($file->getSize() / 1024);
$file_ex = $file->getClientOriginalExtension();
$file_mime = $file->getMimeType();

if (!in_array($file_ex, array('jpg', 'gif', 'png'))) return Redirect::to('/')->withErrors('Invalid image extension we just allow JPG, GIF, PNG');

 $newname = $file_name;
 $file->move(URL::to('/').'/uploads/', $newname);
Run Code Online (Sandbox Code Playgroud)

上传文件夹存在。

php upload file laravel

0
推荐指数
1
解决办法
8683
查看次数

Java可运行的问题

目前这是我的代码

package com.raggaer.frame;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFrame;

public class Frame {

    private JFrame frame;

    public Frame() {

        this.frame = new JFrame("Java Snake");
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
        this.frame.add(new Panel());

        Paint game = new Paint();

        this.frame.setResizable(false);
        this.frame.pack();
        this.frame.setVisible(true);

    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的油漆课

package com.raggaer.frame;

public class Paint implements Runnable {

    private Thread thread;

    public Paint() {

        thread = new Thread(this);
        thread.start();
    }

    public void run() {

        System.out.println("aaa");

    }

}
Run Code Online (Sandbox Code Playgroud)

但是System.out.println("aaa"); 只是执行一次而不是永远..我做错了什么?

java multithreading runnable

0
推荐指数
1
解决办法
308
查看次数

标签 统计

c# ×3

go ×3

image ×2

base64 ×1

colors ×1

file ×1

get ×1

java ×1

laravel ×1

list ×1

methods ×1

multithreading ×1

php ×1

return ×1

rgba ×1

runnable ×1

set ×1

string ×1

synchronization ×1

upload ×1