简体   繁体   English

谁能告诉我为什么我不能从项目外部访问此代码?

[英]Can anyone tell me why I cant access this code from outside of it's project?

I found some code online for image searching/recognition and since I do not know barely any csharp I put it in a class and built it. 我在网上找到了一些用于图像搜索/识别的代码,由于我几乎不了解任何尖锐的特性,因此将其放在一个类中并进行了构建。 Now when I try to access it from a vb project it does not show up. 现在,当我尝试从vb项目访问它时,它不会显示。 Even after it is referenced I cannot actually access it. 即使引用了它,我实际上也无法访问它。 I am geussing because the functions are not shared, and as I understand "Static" in C# is the same as "Shared in vb.net. Although when adding it in I get errors. Can anyone confirm if this is the issue why I can't access it?? Same goes for when I referenced this proejct from my vb.net project I could not access the classes either. 我很困惑,因为这些功能没有共享,并且据我了解,C#中的“静态”与vb.net中的“共享”相同。尽管在添加时出现错误。任何人都可以确认这是否是我可以解决的问题“不能访问它?”当我从vb.net项目中引用此项目时,同样如此,我也无法访问这些类。

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;


namespace ImageRecognition
{
class LockedFastImage
{
    private Bitmap image;
    private byte[] rgbValues;
    private System.Drawing.Imaging.BitmapData bmpData;

    private IntPtr ptr;
    private int bytes;

    public LockedFastImage(Bitmap image)
    {
        this.image = image;
        Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
        bmpData = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, image.PixelFormat);

        ptr = bmpData.Scan0;
        bytes = Math.Abs(bmpData.Stride) * image.Height;
        rgbValues = new byte[bytes];
        System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
    }

    ~LockedFastImage()
    {
        // Try to unlock the bits. Who cares if it dont work...
        try
        {
            image.UnlockBits(bmpData);
        }
        catch { }
    }

    /// <summary>
    /// Returns or sets a pixel of the image. 
    /// </summary>
    /// <param name="x">x parameter of the pixel</param>
    /// <param name="y">y parameter of the pixel</param>
    public Color this[int x, int y]
    {
        get
        {
            int index = (x + (y * image.Width)) * 4;
            return Color.FromArgb(rgbValues[index + 3], rgbValues[index + 2], rgbValues[index + 1], rgbValues[index]);
        }

        set
        {
            int index = (x + (y * image.Width)) * 4;
            rgbValues[index] = value.B;
            rgbValues[index + 1] = value.G;
            rgbValues[index + 2] = value.R;
            rgbValues[index + 3] = value.A;
        }
    }

    /// <summary>
    /// Width of the image. 
    /// </summary>
    public int Width
    {
        get
        {
            return image.Width;
        }
    }

    /// <summary>
    /// Height of the image. 
    /// </summary>
    public int Height
    {
        get
        {
            return image.Height;
        }
    }

    /// <summary>
    /// Returns the modified Bitmap. 
    /// </summary>
    public Bitmap asBitmap()
    {
        System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
        return image;
    }
}

class ImageChecker
{

    private LockedFastImage big_image;
    private LockedFastImage small_image;
    /// <summary>
    /// The time needed for last operation.
    /// </summary>
    public TimeSpan time_needed = new TimeSpan();

    /// <summary>
    /// Error return value.
    /// </summary>
    static public Point CHECKFAILED = new Point(-1, -1);

    /// <summary>
    /// Constructor of the ImageChecker
    /// </summary>
    /// <param name="big_image">The image containing the small image.</param>
    /// <param name="small_image">The image located in the big image.</param>
    public ImageChecker(Bitmap big_image, Bitmap small_image)
    {
        this.big_image = new LockedFastImage(big_image);
        this.small_image = new LockedFastImage(small_image);
    }

    /// <summary>
    /// Returns the location of the small image in the big image. Returns CHECKFAILED if not found.
    /// </summary>
    /// <param name="x_speedUp">speeding up at x achsis.</param>
    /// <param name="y_speedUp">speeding up at y achsis.</param>
    /// <param name="begin_percent_x">Reduces the search rect. 0 - 100</param>
    /// <param name="end_percent_x">Reduces the search rect. 0 - 100</param>
    /// <param name="begin_percent_x">Reduces the search rect. 0 - 100</param>
    /// <param name="end_percent_y">Reduces the search rect. 0 - 100</param>
    public Point bigContainsSmall(int x_speedUp = 1, int y_speedUp = 1, int begin_percent_x = 0, int end_percent_x = 100, int begin_percent_y = 0, int end_percent_y = 100)
    {
        /*
         * SPEEDUP PARAMETER
         * It might be enough to check each second or third pixel in the small picture.
         * However... In most cases it would be enough to check 4 pixels of the small image for diablo porposes.
         * */

        /*
         * BEGIN, END PARAMETER
         * In most cases we know where the image is located, for this we have the begin and end paramenters.
         * */

        DateTime begin = DateTime.Now;

        if (x_speedUp < 1) x_speedUp = 1;
        if (y_speedUp < 1) y_speedUp = 1;
        if (begin_percent_x < 0 || begin_percent_x > 100) begin_percent_x = 0;
        if (begin_percent_y < 0 || begin_percent_y > 100) begin_percent_y = 0;
        if (end_percent_x < 0 || end_percent_x > 100) end_percent_x = 100;
        if (end_percent_y < 0 || end_percent_y > 100) end_percent_y = 100;

        int x_start = (int)((double)big_image.Width * ((double)begin_percent_x / 100.0));
        int x_end = (int)((double)big_image.Width * ((double)end_percent_x / 100.0));
        int y_start = (int)((double)big_image.Height * ((double)begin_percent_y / 100.0));
        int y_end = (int)((double)big_image.Height * ((double)end_percent_y / 100.0));

        /*
         * We cant speed up the big picture, because then we have to check pixels in the small picture equal to the speeded up size 
         * for each pixel in the big picture.
         * Would give no speed improvement.
         * */

        //+ 1 because first pixel is in picture. - small because image have to be fully in the other image
        for (int x = x_start; x < x_end - small_image.Width + 1; x++)
            for (int y = y_start; y < y_end - small_image.Height + 1; y++)
            {
                //now we check if all pixels matches
                for (int sx = 0; sx < small_image.Width; sx += x_speedUp)
                    for (int sy = 0; sy < small_image.Height; sy += y_speedUp)
                    {
                        if (small_image[sx, sy] != big_image[x + sx, y + sy])
                            goto CheckFailed;
                    }

                //check ok
                time_needed = DateTime.Now - begin;
                return new Point(x, y);

            CheckFailed: ;
            }

        time_needed = DateTime.Now - begin;
        return CHECKFAILED;
    }
}

} }

You're not adding the public access modifier to your classes, which are thus automatically declared as internal . 您没有在类中添加public access修饰符,因此它们会自动声明为internal Fix it and everything should work. 修复它,一切都会正常。

Example: 例:

public class LockedFastImage { /*Your code...*/}

You haven't specified any access specifier with your class, thus by default your class is internal that is why you can't access it outside the assembly. 您尚未在类中指定任何访问说明符,因此默认情况下您的类是internal类,这就是为什么您不能在程序集外部访问它。

For classes and structs Access Modifier - MSDN 对于类和结构访问修饰符-MSDN

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. 直接在名称空间中声明的类和结构(换句话说,未嵌套在其他类或结构中)可以是公共的或内部的。 Internal is the default if no access modifier is specified. 如果未指定访问修饰符,则“内部”为默认设置。

public class LockedFastImage 
{....

You may see Access Modifier C# - MSDN 您可能会看到访问修饰符C#-MSDN

internal 内部

The type or member can be accessed by any code in the same assembly, but not from another assembly. 可以通过同一程序集中的任何代码访问类型或成员,但不能从另一个程序集中访问该类型或成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试从 a.csv 读取信息并将其放入 C# 中的数组中。 谁能告诉我为什么代码不起作用? - I am trying to read information from a .csv and put it into an array in C#. Can anyone tell me why the code doesn't work? 任何人都可以告诉我这部分代码有什么问题 - Can anyone tell me what's wrong in this part of code 谁能告诉我为什么此代码的可维护性指数仅为40? - Can anyone tell me why the maintainability index is only 40 for this code? 谁能告诉我为什么这不能解决 Project Euler 的问题 8? - Can anyone tell me why this doesn't work to solve Problem 8 of Project Euler? 谁能告诉我这个更新声明有什么问题? 访问数据库 - Can anyone tell me what's wrong with this Update Statement? Access Mdb 谁能告诉我为什么我的触发器没有按照我的预期工作? - Can anyone tell me why my triggers are not working the way I intended them to? 谁能告诉我这段代码在c#中到底意味着什么? - Can anyone tell me what exactly this code means in c#? 谁能告诉我这个ZeroMQ代码有什么问题吗? - Can anyone tell me what is wrong with this ZeroMQ code? 谁能告诉我为什么我的令牌 API 返回 null? - Can anyone tell me why my token API is returning null? 谁能告诉我为什么我的XML编写器不编写属性? - Can anyone tell me why my XML writer is not writing attributes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM