نمایش نتایج 1 تا 6 از 6

نام تاپیک: بدست آوردن تعداد پیکسلهای یک رنگ مشخص از تصویر بیت مپ

  1. #1
    کاربر دائمی آواتار (سیدشریفی)
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تبریز
    پست
    468

    بدست آوردن تعداد پیکسلهای یک رنگ مشخص از تصویر بیت مپ

    با سلام
    در وی بی توابعی وجود دارد که میتوان تصاویری را که Indexed Color شده اند (منظورم تصاویر بیت مپ میباشد) بعضی از مشخصاتش را فهمید بطور مثال عرض و طول و شماره رنگ و غیره .
    حال میخواستم ببینم آیا میشود تعداد پیکسلهای بکار رفته در یک رنگ مشخص را هم فهمید .
    یک روش خواندن تک تک پیکسلهای تصویر میباشد ولی خیلی زمان میبرد و من میخواهم سریعتر این کار را انجام دهم .
    لطفا کمکم کنید .
    :(

  2. #2
    کاربر دائمی آواتار (سیدشریفی)
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تبریز
    پست
    468
    لطفا جواب بدید .
    :(

  3. #3
    کاربر دائمی آواتار (سیدشریفی)
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تبریز
    پست
    468
    حداقل بگید اینکار شدنی است یا خیر .
    تا من دنبال راه حل دیگه ای باشم .
    :? :(

  4. #4

    Graphics Programming in Visual Basic - Setting and Getting Pixels

    By: Tanner Helland

    Despite what many programmers will tell you, Visual Basic is an excellent programming language for high-end graphic applications. Its easy-to-use interface and programming language allows you to quickly and accurately create all sorts of neat programs without having to worry about the mess of C++‎ syntax. Also, you can use a number of easy API calls to speed up your interface to professional speed. So, here's part of how to become a professional graphics programmer using only VB.

    -THE EASY WAY TO DO PIXEL STUFF-

    This tutorial will go through the basic way to get and set pixels in Visual Basic. You will use both VB and the Windows API and see the differences between both methods. While this way of getting and setting pixels is slower then the forthcoming part 2 of this tutorial (using GetBitmapBits) it is significantly easier for a beginner, and will still offer impressive results.

    PART I - GETTING COLORS

    Before you can do anything to a picture, you have to first get the color of each pixel. There are two intelligent ways to do this, and both are extremely easy.

    Way 1 - Using VB

    You can use the Point event in VB to get the color of a specified pixel. The format is as follows:

    Color = PictureBox.Point(x,y) | where PictureBox is the name of the picture box or form you want to retrieve the pixel from, and (x,y) are the pixels coordinates. However, this method is quite slow, and for large pictures it will really start to rack up the time. So basically, don't use it. The best way to get pixels is to use the GetPixel API call:

    Way 2 - Using the Windows API

    Private Declare Function GetPixel lib "gdi32" (ByVal hDC as Long, ByVal x as Long, ByVal y as Long) as Long

    Color = GetPixel(PictureBox.hDC, x, y) | where PictureBox is the name of the picture box or form you want to retrieve the pixel from, and (x,y) are the pixels coordinates. This method is many times faster then using VB, and it is basically the same call, except for the API declaration. I will write more on the API call structure in a future tutorial, but for now just trust me. J

    PART II - DRAWING COLORS

    Just as with getting pixels from a picture box or form, there are several ways to set pixels onto an object as well. Again, the internal VB method is very slow compared to the 2 API calls you can use. For you die-hard VB users, the very slow PSet command is the way to go:

    PictureBox.PSet (x,y), Color

    Whereas the API Calls are as follows:

    Private Declare Function SetPixel lib "gdi32" (ByVal hDC as Long, ByVal x as Long, ByVal y as Long, ByVal Color as Long) as Long

    SetPixel PictureBox.hDC, x, y, Color

    Or:

    Private Declare Function SetPixelV lib "gdi32" (ByVal hDC as Long, ByVal x as Long, ByVal y as Long, ByVal Color as Long) as Byte

    SetPixelV PictureBox.hDC, x, y, Color

    The only difference between the two functions, if you notice, is that SetPixel returns a Long (the color that the function was able to set) while SetPixelV returns a byte (whether or not the pixel was set). I would always recommend using SetPixelV, simply because it is slightly faster then SetPixel, but the difference is not very noticeable. So, you should now be able to quickly get and set pixels from any picture box or form, right? But, as always, I have some fun things you can add to the useless programming knowledge section of your brain (heh heh).

    PART III - DRAWING AND GETTING COLORS FROM "SPECIAL" THINGS

    Up until this point we've been relegated to using only picture boxes and forms because they're the only things that have an accessible hDC property, right? Well, there are certain ways to get around that so that we can set pixels on, say, a command button or a check box. To do this, we use the magical 'GetDC' API call:

    Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

    Dim TemporaryHandle as Long

    TemporaryHandle = GetDC(CommandButton.hWnd) OR GetDC(CheckBox.hWnd) OR GetDC(TextBox.hWnd) etc., etc...

    Now you can have all sorts of fun! Say, for some odd reason, that you want to set pixels on a command button. After using the GetDC call to assign a handle to the command button, you can do the SetPixel or SetPixelV call using the variable that contains the newly created hDC and - presto - you can draw on almost anything! Play with that API call for kicks if you ever get bored - it's kind fun...




  5. #5
    کاربر دائمی آواتار (سیدشریفی)
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تبریز
    پست
    468
    با سلام
    از جوابی که دادید خیلی ممنون.
    ولی اگر دقت کرده باشید درون سوالی که پرسیده بودم به این مورد اشاره کرده ام :
    یک روش خواندن تک تک پیکسلهای تصویر میباشد ولی خیلی زمان میبرد و من میخواهم سریعتر این کار را انجام دهم . 

    خواندن تک تک پیکسلهای یک تصویر وقت زیادی را میگیرد و اگر هم تصویر بزرگ باشد که دیگر واویلا .
    من از همین روش خواندن تک تک پیکسلها استفاده میکنم ولی حالا میخواهم سرعت برنامه بالا رود و کاربر پسند باشد .
    لطفا اگر راه حل سریعتری دارد بیان کنید .
    باز هم از جوابی که دادید کمال تشکر را دارم .
    :)

  6. #6
    اگر کمی با DC ها آشنا باشی می توانی این کار را انجام دهی.
    1:توابع مورد نیاز : CreateCompatibleDC , MoveToEx,GetPixel
    متاسفانه الان مقاله ایی در این باب ندارم ولی اگر چیزی پیدا کردم در اختیارت میگذارم :roll:

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •